Removal of onSuccess causes a lot of useEffects #6451
-
I am in the midst of upgrading to version 5. And in each one of these cases, I find myself having to use For example, I have a Select component that accepts I can't find any other solution than Here's another example from our codebase:
Should I just use |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
the general idea here is to derive state:
the If that doesn't work for you, you can also use the
And additionally, your case is a good example of why we removed the callback. I described that in detail in my blog post, but if you add a |
Beta Was this translation helpful? Give feedback.
-
This is by far the dumbest API change in any library I've ever witnessed |
Beta Was this translation helpful? Give feedback.
I have a blogpost on this topic: https://tkdodo.eu/blog/react-query-and-forms
I would prefer the "derived state" solution still:
It's the most simple code. Here, we start the
userSelection
with undefined, because the user hasn't selected anything. Then, we fall back to server state when that's undefined. That means when the query is loaded, the user will see thedefaultSelectedIds
as selected. As soon as they change something,userSelection
will be different thanundefined
, so they will always see the user selection.…