diff --git a/example/src/CustomNode/ColorSelectorNode.js b/example/src/CustomNode/ColorSelectorNode.js index fa5f2447..54ffdacf 100644 --- a/example/src/CustomNode/ColorSelectorNode.js +++ b/example/src/CustomNode/ColorSelectorNode.js @@ -1,30 +1,22 @@ -import React from 'react'; +import React, { memo } from 'react'; import { Handle } from 'react-flow-renderer'; -export default ({ data }) => { +export default memo(({ data }) => { return ( <> console.log('handle onConnect', params)} - /> -
Custom Color Picker Node: {data.color}
- - - console.log('handle onConnect', params)} /> +
+ Custom Color Picker Node: {data.color} +
+ + + ); -}; +}); diff --git a/example/src/Validation/index.js b/example/src/Validation/index.js index 47988e4c..2a46a5d8 100644 --- a/example/src/Validation/index.js +++ b/example/src/Validation/index.js @@ -8,53 +8,43 @@ const initialElements = [ { id: '0', type: 'custominput', position: { x: 0, y: 150 } }, { id: 'A', type: 'customnode', position: { x: 250, y: 0 } }, { id: 'B', type: 'customnode', position: { x: 250, y: 150 } }, - { id: 'C', type: 'customnode', position: { x: 250, y:300 } }, + { id: 'C', type: 'customnode', position: { x: 250, y: 300 } }, ]; +const isValidConnection = (connection) => connection.target === 'B'; + const CustomInput = () => ( <>
Only connectable with B
- connection.target === 'B'} - /> + ); const CustomNode = ({ id }) => ( <> - id === 'B'} - /> +
{id}
- id === 'B'} - /> + ); const HorizontalFlow = () => { const [elements, setElements] = useState(initialElements); - const onConnect = (params) => setElements(els => addEdge(params, els)); + const onConnect = (params) => setElements((els) => addEdge(params, els)); return ( reactFlowInstance.fitView()} + onLoad={(reactFlowInstance) => reactFlowInstance.fitView()} className="validationflow" nodeTypes={{ custominput: CustomInput, - customnode: CustomNode + customnode: CustomNode, }} /> ); -} +}; export default HorizontalFlow; diff --git a/src/components/Nodes/DefaultNode.tsx b/src/components/Nodes/DefaultNode.tsx index 1be3c7ba..7f0fc4f4 100644 --- a/src/components/Nodes/DefaultNode.tsx +++ b/src/components/Nodes/DefaultNode.tsx @@ -1,15 +1,15 @@ -import React from 'react'; +import React, { memo } from 'react'; import Handle from '../../components/Handle'; import { NodeProps, Position } from '../../types'; -const DefaultNode = ({ data, targetPosition = Position.Top, sourcePosition = Position.Bottom }: NodeProps) => ( +const DefaultNode = memo(({ data, targetPosition = Position.Top, sourcePosition = Position.Bottom }: NodeProps) => ( <> {data.label} -); +)); DefaultNode.displayName = 'DefaultNode'; diff --git a/src/components/Nodes/InputNode.tsx b/src/components/Nodes/InputNode.tsx index 8db56ef8..4675493d 100644 --- a/src/components/Nodes/InputNode.tsx +++ b/src/components/Nodes/InputNode.tsx @@ -1,14 +1,14 @@ -import React from 'react'; +import React, { memo } from 'react'; import Handle from '../../components/Handle'; import { NodeProps, Position } from '../../types'; -const InputNode = ({ data, sourcePosition = Position.Bottom }: NodeProps) => ( +const InputNode = memo(({ data, sourcePosition = Position.Bottom }: NodeProps) => ( <> {data.label} -); +)); InputNode.displayName = 'InputNode'; diff --git a/src/components/Nodes/OutputNode.tsx b/src/components/Nodes/OutputNode.tsx index 3276e369..0da2f463 100644 --- a/src/components/Nodes/OutputNode.tsx +++ b/src/components/Nodes/OutputNode.tsx @@ -1,14 +1,14 @@ -import React from 'react'; +import React, { memo } from 'react'; import Handle from '../../components/Handle'; import { NodeProps, Position } from '../../types'; -const OutputNode = ({ data, targetPosition = Position.Top }: NodeProps) => ( +const OutputNode = memo(({ data, targetPosition = Position.Top }: NodeProps) => ( <> {data.label} -); +)); OutputNode.displayName = 'OutputNode'; diff --git a/src/store/index.ts b/src/store/index.ts index be3e9a68..7dec4ecd 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -330,7 +330,9 @@ export const storeModel: StoreModel = { }), updateTransform: action((state, transform) => { - state.transform = [transform.x, transform.y, transform.k]; + state.transform[0] = transform.x; + state.transform[1] = transform.y; + state.transform[2] = transform.k; }), updateSize: action((state, size) => {