4 ms·
Oh great. Another React feature that relies on creating anonymous functions every time your component renders. I presume this is now adequately fast in the var
by lexicality 8y ago
Oh great. Another React feature that relies on creating anonymous functions every time your component renders.
I presume this is now adequately fast in the various JITs in use, because I seem to remember this being one of the major bottlenecks React developers were instructed to avoid doing at all costs.
- dceddia 8y agoYeah, they answer this in the FAQ too. > In modern browsers, the raw performance of closures compared to classes doesn’t differ significantly except in extreme scenarios. 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...
- mlsarecmg 8y agoNah, this has nothing to do with that. If you pass an anonymous fn to a pure-component its shouldComponentUpdate part flags it for re-rendering since the property is new every time, which can be a problem depending on how large its payload is. Creating a function costs you a few clock ticks, there is no bottleneck, rendering a component and its entire sub tree for no reason on the other hand can be critical.
- thatswrong0 8y agoThere’s a useCallback hook for this