Skip to content

Comment on I love React Hooks

Comments

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?

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.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.