/
githubmirror
/
novu
Обзор
Документация
Войти
/
githubmirror
/
novu
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
next
packages/react/src/components/Mounter.tsx
31 строка
712 B
George Desipris
feat(js,react): Export InboxContent component (#6531)
24 сен 2024, 18:29
Не верифицирован
24 сен 2024, 18:29
7225753
Код
Авторство
О чём код?
import { useEffect, useRef } from 'react'; type MounterProps = { mount: (node: HTMLElement) => ((node: HTMLElement) => void) | void; }; /** * Mounter allows you to mount a component to a DOM node. */ export function Mounter({ mount }: MounterProps) { const ref = useRef<HTMLDivElement>(null); useEffect(() => { let unmount: (node: HTMLDivElement) => void | undefined; const element = ref.current; if (element && mount) { const possibleUnmount = mount(element); if (possibleUnmount) { unmount = possibleUnmount; } } return () => { if (element && unmount) { unmount(element); } }; }, [ref, mount]); return <div ref={ref} />; }