useCallback or not

The first consideration is whether the function is tightly coupled to the component. Could you reuse the function elsewhere in your code base? If you could, you might create another js/ts file and export the function for components. I would put it in the component if it is tightly coupled. Whether to use useCallback is another issue.

useCallback is a performance hook. So, the requirement for needing to use it (in my opinion) is when you are dealing with performance issues. This could be an easy win, and it would only require a minor rework. It can help you determine which child components you can skip re-rendering.

See this part of the react docs for more information.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments