Thank for the article but I have a question. What if I mutate the data and I want to fetch the new data? For example I have a api that fetch user profile. When user open their profile and update it, it won't refetch the new data. How can I trigger suspense to fetch new data?
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.
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
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).
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
Thank for the article but I have a question. What if I mutate the data and I want to fetch the new data? For example I have a api that fetch user profile. When user open their profile and update it, it won't refetch the new data. How can I trigger suspense to fetch new data?
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.
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
Hmm you could try setting the
resourcein 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).
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
That's a great approach! Just thought I'd mention it in case you were unaware 🤙
& no thanks needed! Glad I could help 🙌