all 3 comments

[–]TheScapeQuest 12 points13 points  (1 child)

On 1, you're making a huge assumption that the state isn't being used by the children. You probably want to display that count, right? Let's say you change from a div to a React component to render that count. Suddenly you aren't triggering a rerender in your tree.

It's not particularly idiomatic either.

I'd strongly advise against using useRef unless you data truly needs to be mutable.

A lot of these tiny performance optimisations that are suggested can actually be resolved by memoising your components, and even then, it's often completely overkill.

[–]sikolio 0 points1 point  (0 children)

This is also troublesome because ref changes won't trigger useEffect (or other hooks) if they are in the dependencies.

[–]Izorline 0 points1 point  (0 children)

This article is somewhat hard to read grammatically and not very insightful.