function useFunctionHook(fn, countInParent) {
// now the fnCallback will only not change across rerender
const fnCallback = React.useCallback(fn, [countInParent])
const [count, setCount] = React.useState(0);
React.useEffect(() => {
// some logic
// if fnCallback changes the hooks callback will run
}, [count, setCount, fnCallback]);
return [setCount, fnCallback];
}
function App() {
const [countInParent, setCountInParent] = React.useState(0);
function fn() {
// some logic
}
const [setCount] = useFunctionHook(fn, countInParent);
return (
<div>
some child component inside.
</div>
);
}
Created
December 25, 2019 10:30
-
-
Save simbathesailor/e784b4b8b57a06eeb30959f10776ac36 to your computer and use it in GitHub Desktop.
blog4.md
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment