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
Smelvin
Smelvin2w ago
Would you be able to give more context, or share your app URL?
Dash
DashOP2w ago
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:
async onClick = (e) => {
await api.<model>.bulkUpsert(...);
};
async onClick = (e) => {
await api.<model>.bulkUpsert(...);
};
No setState or other state updating, but still I got my entire page updated for some reason...
Smelvin
Smelvin2w ago
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
Dash
DashOP3d ago
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
Smelvin
Smelvin3d ago
Happy to hear it!

Did you find this page helpful?