0
2
JRJose Romero
reacthookmemoizationβ’β’β’
React TypeScript RecipesReturns a memoized callback.
Pass an inline callback and an array of dependencies. useCallback
will return a memoized version of the callback that only changes if one of the dependencies has changed. This is useful when passing callbacks to optimized child components that rely on reference equality to prevent unnecessary renders (e.g. shouldComponentUpdate).
Library: react
Shortcut: react.hook.callback.use
import { useCallback } from "react";
const memoizedCallback = useCallback(() => {
doSomething(dependency1, dependency2);
},
[dependency1, dependency2],
);