@mui/x-data-grid
Version:
The Community plan edition of the MUI X Data Grid components.
28 lines (27 loc) • 870 B
JavaScript
'use client';
import * as React from 'react';
import { useFirstRender } from "../../utils/useFirstRender.js";
export const useGridRegisterPipeApplier = (apiRef, group, callback) => {
const cleanup = React.useRef(null);
const id = React.useRef(`mui-${Math.round(Math.random() * 1e9)}`);
const registerPreProcessor = React.useCallback(() => {
cleanup.current = apiRef.current.registerPipeApplier(group, id.current, callback);
}, [apiRef, callback, group]);
useFirstRender(() => {
registerPreProcessor();
});
const isFirstRender = React.useRef(true);
React.useEffect(() => {
if (isFirstRender.current) {
isFirstRender.current = false;
} else {
registerPreProcessor();
}
return () => {
if (cleanup.current) {
cleanup.current();
cleanup.current = null;
}
};
}, [registerPreProcessor]);
};