devextreme-react
Version:
DevExtreme UI and Visualization Components for React
55 lines (53 loc) • 1.77 kB
JavaScript
/*!
* devextreme-react
* Version: 26.1.3
* Build date: Wed Jun 10 2026
*
* Copyright (c) 2012 - 2026 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
*/
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, };