Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not properly working together with <React.Supsense> component #52

Open
simonsystem opened this issue Jan 3, 2024 · 0 comments
Open

Comments

@simonsystem
Copy link

simonsystem commented Jan 3, 2024

I'm trying to keep my application rendered with a global loading animation, as long as I can.

But when throwing that pending Promise first, no more requests are made and no more data is fetched from feathers server. Because that component isn't mounted yet, the useEffect() hook inside of figbirds useQuery() function is never called.

// ./src/App.tsx
import React from 'react';
import MyComponent from './MyComponent';

const App: React.FC<{}> = () => (
  <React.Suspense fallback={<h1>loading ...</h1>}>
    <MyComponent userId="1" />
  </React.Suspense>
);
export default App;
// ./src/MyComponent.tsx
import React from 'react';
import { useFind, useGet } from 'figbird';
const pending = new Promise(() => {});

const MyComponent: React.FC<{ userId: string }> = ({ userId }) => {
  const result = useGet('user', userId);
  if (result.isFetching) throw pending;
  
  return (
    <h1>Hello {result.data.username}</h1>
  );
};
export default MyComponent;

On searching for issues, I found this: facebook/react#18749 (comment)

This is expected. useEffect is triggered after a component is rendered and committed. If it is suspended, it's not going to happen

Can we please rewrite figbird not to start that feathers request inside of a useEffect() hook, instead let's use e.g. the use() hook on a Promise, like here https://react.dev/reference/react/use ? That could fix it, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant