Re:I love React Hooks
by alangpierce on Wednesday February 20, 2019 @12:35AM
(#19205806)
Part of the point of solutions #1 and #3 is that they pass in exactly the same function on each render, so it's possible to avoid unnecessary rendering further down by knowing that the props are the same as before. The hooks solution will make a new handleChange closure each time, so it'll be a different function. Is there are way with hooks to pass the same function each time?
[ Parent
| on HN ]
Re:I love React Hooks
by sophiebits on Wednesday February 20, 2019 @12:43AM
(#19205854)
useCallback is designed for this. useMemo also helps solve the problem from another angle that previously wasn’t as accessible.
Additional reading: https://reactjs.org/docs/hooks-faq.html#are-hooks-slow-becau....
Re:I love React Hooks
by wereHamster on Wednesday February 20, 2019 @12:45AM
(#19205864)
Perhaps the `setText` function remains always the same. I have not checked though.