UNPKG

@mui/x-data-grid

Version:

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

33 lines (32 loc) 1.5 kB
"use strict"; 'use client'; var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default; Object.defineProperty(exports, "__esModule", { value: true }); exports.useGridRegisterStrategyProcessor = void 0; var React = _interopRequireWildcard(require("react")); var _useFirstRender = require("../../utils/useFirstRender"); 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]); (0, _useFirstRender.useFirstRender)(() => { registerPreProcessor(); }); const isFirstRender = React.useRef(true); React.useEffect(() => { if (isFirstRender.current) { isFirstRender.current = false; } else { registerPreProcessor(); } }, [registerPreProcessor]); }; exports.useGridRegisterStrategyProcessor = useGridRegisterStrategyProcessor;