question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow State to be used in dependency lists for React.useEffect, React.useMemo, etc. and as prop for React.memo

See original GitHub issue

First 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:closed
  • Created 3 years ago
  • Comments:22 (20 by maintainers)

github_iconTop GitHub Comments

10reactions
avkonstcommented, Feb 7, 2022

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.

2reactions
avkonstcommented, Feb 26, 2021

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)

Read more comments on GitHub >

github_iconTop Results From Across the Web

You're overusing useMemo: Rethinking Hooks memoization
In some cases, useMemo is irrelevant, overused, and harmful to your application performance. Learn these situations and how to avoid them.
Read more >
useMemo - React Docs
A list of dependencies including every value within your component that's used inside your calculation. On the initial render, the value you'll get...
Read more >
reactjs - When to use useCallback, useMemo and useEffect?
NOTE: functions with useCallback and values with useMemo can be used as dependency in useCallback, useMemo and useEffect.
Read more >
How to manage the useEffect dependency array like a pro?
The useEffect hook allows you to perform side effects in a functional component. There is a dependency array to control when the effect...
Read more >
How to Memoize with React.useMemo() - Dmitri Pavlutin
During initial rendering, useMemo(compute, dependencies) invokes compute , memoizes the calculation result, and returns it to the component. If ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found