Allow State to be used in dependency lists for React.useEffect, React.useMemo, etc. and as prop for React.memo
See original GitHub issueFirst of all, thank you for this awesome lib!
I found myself having difficulties trying to find the right way to implement some state updates efficiently, and the following reflexion arose:
What about using Immer? Thanks to its support for patches, would allow this lib to support a wider range of operations, on all sort of data types. set and merge methods could be replaced by produce, and plugins could leverage patches (which would be useful for my plugin).
I really like the whole intelligent proxy system that is currently in place, and I honestly think that putting Immer in there would make the whole lib even better!
I wonder if this is something possible? Or is there some limitations or willingness to keep everything inside hookstate itself?
Issue Analytics
- State:
- Created 3 years ago
- Comments:22 (20 by maintainers)

Top Related StackOverflow Question
This feature has been finally implemented on a branch. Thanks for XRFoundation sponsoring the development. This will get merged to master and released in Hookstate 4 coming weeks.
I experimented with source code a bit and I think it should be possible to add support for memo as in your example, but it should be opt-in functionality as it will become non-backward compatible. It might even improve performance but it will require keeping references to State objects for longer (to be precise, it will require 2 re-renders (2 updates, same or different, to a state) to get rid of stale State objects related to deleted properties. Now they are cleaned up immediately on the first rerender)