React state refresh after mutation
Hey guys, I need help. Do you experience after executiong bulkUpsert the page will be getting update or the state is getting update instead of specific component? This suddenly happen and I can't find the culprit.
5 Replies
Would you be able to give more context, or share your app URL?
Sure, here's the app URL: polydata.gadget.app
To add more context, I did further investigate and it seems that after calling api.<model>.bulkUpsert(...) in the web/ or frontend side it's making the entire page state to refresh... it's like for some reason all of the useFindMany() got trigger to refresh/invalidate...
Even though I don't have any state updating on that
await api.<model>.bulkUpsert(...)
after execution
The struture of the code something like this:
No setState
or other state updating, but still I got my entire page updated for some reason...So yes that is the behaviour of the Gadgets react hook system, when there is new up to date data it will re-render.
To adjust the request policy you can change the type of request policy that works better for your use case.
I have the docs with the 4 policies and more information here:
https://docs.gadget.dev/reference/react#request-caching
@gadgetinc React - Developer Docs - Gadget
Gadget Docs
I see, thanks for this @[Gadget] Mark, I'll try to mess around with it and get back here about what happen if I fix it.
Thanks again for this @Smelvin, was able to find and fixed the culprit.
Cc @Jordy
Happy to hear it!