@react-three/uikit
Version:
Build performant 3D user interfaces with react-three-fiber and yoga.
25 lines (24 loc) • 1.66 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { forwardRef, useEffect, useMemo, useRef } from 'react';
import { ParentProvider, useParent } from './context.js';
import { AddHandlers, usePropertySignals } from './utils.js';
import { useComponentInternals } from './ref.js';
import { createContentState, setupContent } from '@pmndrs/uikit/internals';
export const Content = forwardRef((properties, ref) => {
const parent = useParent();
const outerRef = useRef(null);
const innerRef = useRef(null);
const propertySignals = usePropertySignals(properties);
const internals = useMemo(() => createContentState(parent, propertySignals.style, propertySignals.properties, propertySignals.default, innerRef), [parent, propertySignals]);
internals.interactionPanel.name = properties.name ?? '';
useEffect(() => {
if (outerRef.current == null || innerRef.current == null) {
return;
}
const abortController = new AbortController();
setupContent(internals, parent, propertySignals.style, propertySignals.properties, outerRef.current, innerRef.current, abortController.signal);
return () => abortController.abort();
}, [internals, parent, propertySignals]);
useComponentInternals(ref, parent.root, propertySignals.style, internals, internals.interactionPanel);
return (_jsxs(AddHandlers, { handlers: internals.handlers, ref: outerRef, children: [_jsx("primitive", { object: internals.interactionPanel }), _jsx("object3D", { matrixAutoUpdate: false, ref: innerRef, children: _jsx(ParentProvider, { value: undefined, children: properties.children }) })] }));
});