Eli Elad Elrom
Feb 17, 2021

--

Thanks for the article. Using reference current in useEffect hook is an unnecessary dependency and if you go ahead and remove that dependency the code would be the same and actually better.

The reason is that mutable values are not valid dependencies because mutating them doesn't re-render the component.

Meaning if I were to make changes to the current reference the hook would not get called.

What's happening here is that your component will always be going to redraw any data change even if the data is the same.

What I think you really want to do is place a check if the data was changed and only then update the component, I have an article about optimizing React with d3 project that I show three examples of how this can be.

--

--

Eli Elad Elrom
Eli Elad Elrom

No responses yet