Introducing PrimeReact v11-alpha 🎉Discover Now

useUnmountEffect

Run an effect exactly once, when the component unmounts.

Usage#

import { useUnmountEffect } from '@primereact/hooks/use-unmount-effect';
useUnmountEffect(() => {
    socket.close();
});

Equivalent to useEffect(() => cleanup, []), expressed as the cleanup by itself. Reads clearer when the mount path has nothing to do.

Signature#

function useUnmountEffect(effect: React.EffectCallback): void;