Created
October 29, 2018 13:23
-
-
Save simon-robertson/b0947ea7c2387a13e8fbc09457d742e6 to your computer and use it in GitHub Desktop.
React 16.7.0-alpha `useLifeCycle` hook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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