UNPKG

@e-group/hooks

Version:

eGroup team react-hooks that share across projects.

23 lines (20 loc) 849 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = useOnMount; var _react = require("react"); /** * Hook to run a handler once on mount and never again. * See https://reactjs.org/docs/hooks-reference.html#useeffect * See https://github.com/facebook/create-react-app/issues/6880 * This function is mainly to provide a better signal to the developer than * knowing how `useEffect` works when you pass an empty array. It also helps to * get around warnings raised by `react-hooks/exhaustive-deps` and we use it * instead of `// eslint-disable-next-line react-hooks/exhaustive-deps`. * We only run the handler once, so we don't care if dependencies change! */ function useOnMount(handler) { // eslint-disable-next-line react-hooks/exhaustive-deps return (0, _react.useEffect)(handler, []); }