Skip to content

Instantly share code, notes, and snippets.

@erickvieira
Last active September 22, 2020 23:11
Show Gist options
  • Save erickvieira/5052eb42429a4517e94c1f459faa9683 to your computer and use it in GitHub Desktop.
Save erickvieira/5052eb42429a4517e94c1f459faa9683 to your computer and use it in GitHub Desktop.
React Hooks for lifecycle abstractions
import { useEffect, useCallback } from "react";
export default function (effect: () => void | Promise<void>) {
const mountEffect = useCallback(() => {
effect();
}, [effect]);
useEffect(mountEffect, []);
}
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