function useFunctionHook(fn) {
const [count, setCount] = React.useState(0);
React.useEffect(() => {
// some logic
// if fn changes the hooks callback will run
}, [count, setCount, fn]);
return [setCount, fn];
}
function App() {
const [countInParent, setCountInParent] = React.useState(0);
function fn() {
// some logic
}
const [setCount] = useFunctionHook(fn);
return (
<div>
some child component inside.
</div>
);
}
Created
December 27, 2019 06:11
-
-
Save simbathesailor/c63c46028c5f2a099f29b652c82d9e78 to your computer and use it in GitHub Desktop.
blog16.md
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment