Replies: 1 comment 7 replies
-
If it behaves differently then you might lose user input. Example scenario:
|
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi. As per the Form docs, form.initialize(...) can only be called once, next calls are ignored:
Why is it so? It caused me several hours investigations.
The issue is that TanStack Query by default provides cached data in response if present (which is a good behavior), then in the background fetches the fresh data and provides it once ready, triggering re-render. With Mantine, it seems logical to do useEffect on query data changes to call form.initialize(...). But with the current Mantine form.initialize(...) behavior when you open a page with a cached data present (for example, come back to the page), you're first given the cached data, which form.initialize(...) accepts with no issue, but then the second form.initialize(...) call with fresh data is ignored.
Even though Mantine docs do mention it in the "Example with TanStack Query (react-query):", such behavior basically makes it impractical to use? So really it means the current example in the docs is there, but shouldn't be used by anyone in production. (unless somebody disables query caching, which is rare I believe)
The workaround is instead of form.initialize(newValues) do:
Why does form.initialize have such behavior that is basically not optimized for the common use case with TanStack Query?
Beta Was this translation helpful? Give feedback.
All reactions