UNPKG

@mui/x-data-grid

Version:

The Community plan edition of the MUI X Data Grid components.

26 lines (25 loc) 1.17 kB
'use client'; import * as React from 'react'; import { useFirstRender } from "../../utils/useFirstRender.mjs"; export const useGridRegisterStrategyProcessor = (apiRef, strategyName, group, processor) => { const registerPreProcessor = React.useCallback(() => { // NOTE: the unregister fn is intentionally discarded. Unlike pipe processors // (which are additive), a strategy processor is required for as long as its // strategy is active — `applyStrategyProcessor` throws if the active strategy's // processor is missing — so it must outlive the registering component. The cache // keeps a single entry per (processor, strategy) and is reclaimed with the grid // api, so nothing leaks; `void` documents the deliberate discard. void apiRef.current.registerStrategyProcessor(strategyName, group, processor); }, [apiRef, processor, group, strategyName]); useFirstRender(() => { registerPreProcessor(); }); const isFirstRender = React.useRef(true); React.useEffect(() => { if (isFirstRender.current) { isFirstRender.current = false; } else { registerPreProcessor(); } }, [registerPreProcessor]); };