UNPKG

devextreme-react

Version:

DevExtreme React UI and Visualization Components

55 lines (53 loc) 1.81 kB
/*! * devextreme-react * Version: 25.2.3 * Build date: Fri Dec 12 2025 * * Copyright (c) 2012 - 2025 Developer Express Inc. ALL RIGHTS RESERVED * * This software may be modified and distributed under the terms * of the MIT license. See the LICENSE file in the root of the project for details. * * https://github.com/DevExpress/devextreme-react */ import * as React from 'react'; import { useImperativeHandle, forwardRef, useRef, useLayoutEffect, useCallback, } from 'react'; import { ComponentBase } from './component-base'; // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types function elementIsExtension(el) { return el.type?.componentType === 'extension'; } const ExtensionComponent = forwardRef( // eslint-disable-next-line @stylistic/max-len (props, ref) => { const componentBaseRef = useRef(null); const createWidget = useCallback((el) => { componentBaseRef.current?.createWidget(el); }, []); useLayoutEffect(() => { const { onMounted } = props; if (onMounted) { onMounted(createWidget); } else { createWidget(); } }, []); const createWidgetRef = useRef(createWidget); useLayoutEffect(() => { createWidgetRef.current = createWidget; }, [createWidget]); useImperativeHandle(ref, () => ({ getInstance() { return componentBaseRef.current?.getInstance(); }, getElement() { return componentBaseRef.current?.getElement(); }, createWidget(el) { createWidgetRef.current?.(el); }, }), []); return (React.createElement(ComponentBase, { ref: componentBaseRef, ...props })); }); export { ExtensionComponent, elementIsExtension, };