mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
15 lines
507 B
TypeScript
15 lines
507 B
TypeScript
import { omit } from 'lodash';
|
|
import React from 'react';
|
|
|
|
export default function DomComponent(props: React.HTMLAttributes<HTMLDivElement> & { childDom: HTMLElement }) {
|
|
const [dom, setDom] = React.useState<HTMLElement | null>(null);
|
|
React.useEffect(() => {
|
|
if (!dom) return;
|
|
dom.appendChild(props.childDom);
|
|
return () => { // eslint-disable-line consistent-return
|
|
dom.removeChild(props.childDom);
|
|
};
|
|
}, [dom]);
|
|
return <div {...omit(props, 'childDom')} ref={setDom}></div>;
|
|
}
|