Skip to content

Instantly share code, notes, and snippets.

@simon-robertson
Created October 29, 2018 13:23
Show Gist options
  • Save simon-robertson/b0947ea7c2387a13e8fbc09457d742e6 to your computer and use it in GitHub Desktop.
Save simon-robertson/b0947ea7c2387a13e8fbc09457d742e6 to your computer and use it in GitHub Desktop.
React 16.7.0-alpha `useLifeCycle` hook
export const useLifeCycle = (initialize, values) => {
const { mount, unmount, update } = useMemo(initialize, []);
useEffect(() => {
if (typeof mount === 'function') {
mount(values);
}
return () => {
if (typeof unmount === 'function') {
unmount(values);
}
};
}, []);
useEffect(() => {
if (typeof update === 'function') {
update(values);
}
});
return null;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment