Introducing PrimeReact v11-alpha 🎉Discover Now

useMountEffect

Run an effect exactly once, after the first render.

Usage#

import { useMountEffect } from '@primereact/hooks/use-mount-effect';
useMountEffect(() => {
    console.log('mounted');
 
    return () => console.log('cleanup');
});

Equivalent to useEffect(fn, []) but reads clearer at the call site. The optional return value is treated as the cleanup function, just like useEffect.

Signature#

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