DEV Community

Discussion on: React Native Performance Optimisation With Hooks

Collapse
 
alebagran profile image
alebagran • Edited

The after code of the first solution is still wrong, because the functions will still have new references every time the functional component is called, since both awesomeChildListRenderItem and awesomeChildListKeyExtractor will be redeclared.

One option to solve this is to declare the functions outside of the component. But in the case of awesomeChildListRenderItem, it is using setChildState, which can only be accessed from within the component scope. In this particular case only, you can use useCallback instead.

Collapse
 
ltsharma profile image
Lakshmeesha

That's true with respect to th example i have in this article, in real case, its not fissile to use each & every function outside component, functions will somehow depends on the state & in that case that function will be called.
that's what the dependency array of useCallback does, if there is change in dependency, useCallback returns new function.