// @flow strict import * as React from 'react'; export const ManagerReferenceNodeContext: React.Context = React.createContext(); export const ManagerReferenceNodeSetterContext: React.Context< void | ((?Element) => void) > = React.createContext(); export type ManagerProps = $ReadOnly<{ children: React.Node, }>; export function Manager({ children }: ManagerProps): React.Node { const [referenceNode, setReferenceNode] = React.useState(null); const hasUnmounted = React.useRef(false); React.useEffect(() => { return () => { hasUnmounted.current = true; }; }, []); const handleSetReferenceNode = React.useCallback((node) => { if (!hasUnmounted.current) { setReferenceNode(node); } }, []); return ( {children} ); }