UNPKG

@mui/x-internals

Version:

Utility functions for the MUI X packages (internal use only).

21 lines (19 loc) 532 B
'use client'; import * as React from 'react'; /** * Run an effect only after the first render. * * @param effect The effect to run after the first render * @param deps The dependencies for the effect */ export function useEffectAfterFirstRender(effect, deps) { const isFirstRender = React.useRef(true); React.useEffect(() => { if (isFirstRender.current) { isFirstRender.current = false; return undefined; } return effect(); // eslint-disable-next-line react-hooks/exhaustive-deps }, deps); }