@mui/x-data-grid
Version:
The community edition of the data grid component (MUI X).
20 lines (16 loc) • 617 B
JavaScript
import { buildWarning } from '../../utils/warning';
function isOutputSelector(selector) {
return selector.acceptsApiRef;
}
const stateNotInitializedWarning = buildWarning(['MUI: `useGridSelector` has been called before the initialization of the state.', 'This hook can only be used inside the context of the grid.']);
export const useGridSelector = (apiRef, selector) => {
if (process.env.NODE_ENV !== 'production') {
if (!apiRef.current.state) {
stateNotInitializedWarning();
}
}
if (isOutputSelector(selector)) {
return selector(apiRef);
}
return selector(apiRef.current.state);
};