Skip to content

How to type a custom produce function? #898

Description

@alexturpin

🙋‍♂ 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 with use-immer's DraftFunction but use-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 from updateState?

Environment

Latest React and Immer.

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions