Suspense and refresh of data.
Unanswered
Spectacled bear posted this in #help-forum
Spectacled bearOP
I'm looking for at good way to use suspense for the initial dataload and then a way to refresh the data without triggering the supense again.
If I use a promise the suspense works (data is Promise<string> that is fetched from a server)
But then how do i "refresh" the data either by interval or by button action?
If I give a fetchData async function (function fetchData(): Promise<string>)
Then I can't get suspense to work, but I can then use the function to update with setState.
The refresh button / interval does not need to be inside the Home, it can be outside if that makes it easier 🙂
If I use a promise the suspense works (data is Promise<string> that is fetched from a server)
<Suspense fallback={<div>Loading...</div>}>
<Home data={data} />
</Suspense>But then how do i "refresh" the data either by interval or by button action?
If I give a fetchData async function (function fetchData(): Promise<string>)
<Suspense fallback={<div>Loading...</div>}>
<Home fetchData={fetchData} />
</Suspense>Then I can't get suspense to work, but I can then use the function to update with setState.
The refresh button / interval does not need to be inside the Home, it can be outside if that makes it easier 🙂
2 Replies
Western paper wasp
hi. You cannot “refresh Promise” without rerunning Suspense, initial loading via Suspense, then state/SWR
To refresh without falling back again, keep the data in client state or
useSWR/ReactQuery, use Suspense once for the initial load, then update the data via state/revalidate, don't touch Suspense anymore