Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { useEffect, useRef } from 'react';
- export function useUnmountEffect(callback: () => void) {
- const callbackRef = useRef(callback);
- callbackRef.current = callback;
- useEffect(() => {
- return () => {
- const callbackFunction = callbackRef.current;
- if (!callbackFunction) {
- return;
- }
- callbackFunction();
- };
- }, []);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement