DEV Community

Discussion on: Creating better user experiences with React 18 Suspense and Transitions

Collapse
 
tmns profile image
tmns

Hey there! If you can provide a CodeSandbox / StackBlitz I can give your code a look. Without that, it's a bit difficult to point you in the right direction.

Collapse
 
hadius profile image
Dương

Sandbox: codesandbox.io/s/wonderful-wescoff...
Currently, I have tried to use state to set the page and pageSize, but it will stuck in an infinite loop

Thread Thread
 
tmns profile image
tmns

Hmm you could try setting the resource in state, so that when you update it (via a transition) it triggers a rerender. For example with your code, something like this. I added some comments to explain what's going on as well. Hope it helps!

Also, in case you haven't already, I'd suggest looking into react-query. It handles refetching on mutation automatically for you and has built in support for Suspense Data Fetching (enabled via a config option).

Thread Thread
 
hadius profile image
Dương

I have read about react query, swr with suspense, but I want to learn suspense natively so I try not to use those library.
Btw, thank for your support, I really appreciate it

Thread Thread
 
tmns profile image
tmns

That's a great approach! Just thought I'd mention it in case you were unaware 🤙

& no thanks needed! Glad I could help 🙌