Hacker News new | ask | show | jobs
by alangpierce 2720 days ago
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?
2 comments

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....

Perhaps the `setText` function remains always the same. I have not checked though.