You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Hydro/packages/ui-default/components/react/DomComponent.tsx

19 lines
597 B
TypeScript

import React from 'react';
import { omit } from 'lodash';
const tempDoms = {};
export default function DomComponent(props: React.HTMLAttributes<HTMLDivElement> & { id?: string, childDom: HTMLElement }) {
const ref = React.useRef<HTMLDivElement>();
React.useEffect(() => {
let dom = props.childDom;
if (props.id && dom) tempDoms[props.id] = dom;
else if (props.id && !dom && tempDoms[props.id]) dom = tempDoms[props.id];
ref.current.appendChild(dom);
return () => {
$(ref.current).empty();
};
});
return <div {...omit(props, 'childDom')} ref={ref}></div>;
}