devextreme-react
Version:
DevExtreme React UI and Visualization Components
49 lines (47 loc) • 1.63 kB
JavaScript
/*!
* devextreme-react
* Version: 24.2.6
* Build date: Mon Mar 17 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((props, ref) => {
const componentBaseRef = useRef(null);
const createWidget = useCallback((el) => {
componentBaseRef.current?.createWidget(el);
}, [componentBaseRef.current]);
useLayoutEffect(() => {
const { onMounted } = props;
if (onMounted) {
onMounted(createWidget);
}
else {
createWidget();
}
}, []);
useImperativeHandle(ref, () => ({
getInstance() {
return componentBaseRef.current?.getInstance();
},
getElement() {
return componentBaseRef.current?.getElement();
},
createWidget(el) {
createWidget(el);
},
}), [componentBaseRef.current, createWidget]);
return (React.createElement(ComponentBase, { ref: componentBaseRef, ...props }));
});
export { ExtensionComponent, elementIsExtension, };