How to view defer
loading state, similar to loader
with useNavigate
#7563
Unanswered
cliffordfajardo
asked this question in
Q&A
Replies: 2 comments
-
same question here, havent found a solution :( |
Beta Was this translation helpful? Give feedback.
0 replies
-
The main issue here is that the deferred value (promise) does not trigger a state update when it resolves. I had the same problem and I've achieved this by using useEffect and awaiting the promise directly. In the original example it would be like this: const SomeComponentWhereDeferDataWillRender = ({ setIsLoading }) => {
useEffect(() => {
(async () => {
await somePromise;
setIsLoading(false);
})();
}, [setIsLoading, somePromise]);
return (
<Suspense fallback={<div>Loading...</div>}>
<Await resolve={somePromise}> {(resolvedValue) => <p>{resolvedValue}</p>}</Await>
</Suspense>
);
}
const PageComponent = () => {
const [isLoading, setIsLoading] = useState(true);
return (
<TopNav isLoading={isLoading} />
<SomeComponentWhereDeferDataWillRender setIsLoading={setIsLoading} />
);
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Background Context
For example I know with loader you can use useNavigate to see if some data is in progress
However, is there a similar way to hook into the progress of data that is coming from
defer
?Use case: implement a spinner outside of where the stream'd data is rendered
When I hook into
useNavigate
it doesnt seem to update when I make a page transition:defer
idle
Stackblitz Code
defer-data.mp4
References
Beta Was this translation helpful? Give feedback.
All reactions