3 ms·
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
by alangpierce 8y 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?
- sophiebits 8y agouseCallback 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-because-of-creating-functions-in-render https://reactjs.org/docs/hooks-faq.html#are-hooks-slow-becau....
- wereHamster 8y agoPerhaps the `setText` function remains always the same. I have not checked though.