feat(node-editor): fit view on init

This commit is contained in:
blessedcoolant 2023-07-11 18:22:50 +12:00
parent c3adb301a0
commit acea304348

View File

@ -7,8 +7,10 @@ import {
OnConnectEnd,
OnConnectStart,
OnEdgesChange,
OnInit,
OnNodesChange,
ReactFlow,
ReactFlowInstance,
} from 'reactflow';
import {
connectionEnded,
@ -67,6 +69,10 @@ export const Flow = () => {
dispatch(connectionEnded());
}, [dispatch]);
const onInit: OnInit = useCallback((v: ReactFlowInstance) => {
if (v) v.fitView();
}, []);
return (
<ReactFlow
nodeTypes={nodeTypes}
@ -77,6 +83,7 @@ export const Flow = () => {
onConnectStart={onConnectStart}
onConnect={onConnect}
onConnectEnd={onConnectEnd}
onInit={onInit}
defaultEdgeOptions={{
style: { strokeWidth: 2 },
}}