You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey folks. I'm using Immer with React and I want to create a custom produce function that does something with the new state. I want to pass this produce function down to components so they can call it to update the state, and so that I can do something with the newly updated state. I can't seem to figure out how to type that function however. It seems that ValidRecipeReturnType isn't exported. I was able to do it with use-immer's DraftFunction but use-immer doesn't return the new state after it's set.
If the new state is computed using the previous state, you can pass a function to setState. The function will receive the previous value, and return an updated value.
This is important because the state update can now run outside of the render context/timing. I'm not a react render wizard, so I can't tell you how this affects batching or render timing, but it's good to use the callback notation when computing the next state from the previous. Good luck!
🙋♂ Question
Hey folks. I'm using Immer with React and I want to create a custom produce function that does something with the new state. I want to pass this produce function down to components so they can call it to update the state, and so that I can do something with the newly updated state. I can't seem to figure out how to type that function however. It seems that
ValidRecipeReturnType
isn't exported. I was able to do it withuse-immer
'sDraftFunction
butuse-immer
doesn't return the new state after it's set.Link to repro
https://codesandbox.io/s/festive-browser-v2wj8?file=/src/App.tsx
How can I type the
recipe
param fromupdateState
?Environment
Latest React and Immer.
Thank you!
The text was updated successfully, but these errors were encountered: