Last active
September 22, 2020 23:11
-
-
Save erickvieira/5052eb42429a4517e94c1f459faa9683 to your computer and use it in GitHub Desktop.
React Hooks for lifecycle abstractions
This file contains 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
import { useEffect, useCallback } from "react"; | |
export default function (effect: () => void | Promise<void>) { | |
const mountEffect = useCallback(() => { | |
effect(); | |
}, [effect]); | |
useEffect(mountEffect, []); | |
} |
This file contains 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
import { useEffect, useCallback } from "react"; | |
export default function (effect: () => void) { | |
const unmountEffect = useCallback(() => effect, [effect]); | |
useEffect(unmountEffect, []); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment