Skip to content

Instantly share code, notes, and snippets.

@amass01
Created July 5, 2020 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amass01/0d7fbbfb05f5cd0618906d992e3e7693 to your computer and use it in GitHub Desktop.
Save amass01/0d7fbbfb05f5cd0618906d992e3e7693 to your computer and use it in GitHub Desktop.
import { useEffect } from "react";
/**
* useMountEffect is a custom hook to run an effect on mount
* only once, it accepts an effect/function and executes it
* only after succesful mount (empty array as second argument
* in useEffect call)
*
* @param {*} fun - effect to run on mount
*/
const useMountEffect = (fun) => useEffect(fun, []);
export default useMountEffect;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment