18 lines
473 B
TypeScript
18 lines
473 B
TypeScript
import { ReactNode } from 'react';
|
|
import { createPortal } from 'react-dom';
|
|
import { ReactFlowState, useStore } from '@reactflow/core';
|
|
|
|
const selector = (state: ReactFlowState) => state.domNode?.querySelector('.react-flow__renderer');
|
|
|
|
function NodeToolbarPortal({ children }: { children: ReactNode }) {
|
|
const wrapperRef = useStore(selector);
|
|
|
|
if (!wrapperRef) {
|
|
return null;
|
|
}
|
|
|
|
return createPortal(children, wrapperRef);
|
|
}
|
|
|
|
export default NodeToolbarPortal;
|