Files
ETB/ETB-FrontEnd/node_modules/@mui/x-data-grid/hooks/utils/useGridApiMethod.js
Iliyan Angelov 306b20e24a Frontend start
2025-09-14 00:54:48 +03:00

25 lines
823 B
JavaScript

import * as React from 'react';
export function useGridApiMethod(apiRef, apiMethods, // TODO: Remove `apiName
// eslint-disable-next-line @typescript-eslint/no-unused-vars
apiName) {
const apiMethodsRef = React.useRef(apiMethods);
const [apiMethodsNames] = React.useState(Object.keys(apiMethods));
const installMethods = React.useCallback(() => {
if (!apiRef.current) {
return;
}
apiMethodsNames.forEach(methodName => {
if (!apiRef.current.hasOwnProperty(methodName)) {
apiRef.current[methodName] = (...args) => apiMethodsRef.current[methodName](...args);
}
});
}, [apiMethodsNames, apiRef]);
React.useEffect(() => {
apiMethodsRef.current = apiMethods;
}, [apiMethods]);
React.useEffect(() => {
installMethods();
}, [installMethods]);
installMethods();
}