React.js useCallback()
useCallback is a React.js Hook. When you have a component with a child repeatedly re-rendering and you pass a callback to it. UseCallback returns a memorized callback. React.useCallback gets a function as the first argument and a dependencies array as a second argument. It will return a new value when the dependencies value changes.
We should not optimize unwanted re-renders without seeing the after effect, optimization always comes with a cost. React.useCallback returns a memorized callback.import React, { useCallback } from 'react';
function MyComponent() {
const handleClick = useCallback(() => {
// handle the click event
}, []);
return <MyChild onClick={handleClick} />;
}
Comments
0 comments
Please Sign in or Create an account to Post Comments