Skip to content

Instantly share code, notes, and snippets.

@simbathesailor
Created December 27, 2019 06:11
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
blog16.md
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>
  );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment