1
0
Fork 0
react-playground/node_modules/@mui/x-internals/esm/useRunOnce/useRunOnce.js
Techognito fc0f69dacb Added Statistics calculation
Statistics now show calculated values
2025-09-04 17:30:00 +02:00

18 lines
No EOL
505 B
JavaScript

import * as React from 'react';
import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
const noop = () => {};
/**
* Runs an effect once, when `condition` is true.
*/
export const useRunOnce = (condition, effect) => {
const didRun = React.useRef(false);
useEnhancedEffect(() => {
if (didRun.current || !condition) {
return noop;
}
didRun.current = true;
return effect();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [didRun.current || condition]);
};