DEV Community

Discussion on: Demystifying React Hooks: useCallback and useMemo

Collapse
 
enricoschaaf profile image
Enrico

Great article! I often see examples, where the submit function of a form is wrapped in a useCallback, but I dont see the reason why someone would do that, any idea?

Collapse
 
milu_franz profile image
Milu • Edited

Hello there! The only reason I can think of is that whoever is implementing the code, does not want their handleFormSubmit() function to be created every time the component re-renders. I found this article where they use the useCallback() hook in a handleFormSubmit() to stop tree invalidation issues. However, I haven't encountered issues when creating a form without using useCallback in the past.