Dynamic number of handle for custom node
See original GitHub issueHi,
I try to custom a node, which would contain a + and - button and would add or remove a “connection ring”. I try something, the first connection ring appears, but not the following. And when I try to connect the first, I have an error.
First I show you my custom node. https://zupimages.net/viewer.php?id=21/44/30yf.png
CustomNode :
import React, { memo, useState } from 'react';
import { Handle, Position } from 'react-flow-renderer';
import Checkbox from '@mui/material/Checkbox';
import ButtonGroup from '@mui/material/ButtonGroup/ButtonGroup';
import Button from '@mui/material/Button/Button';
const IncNode = memo(({ isConnectable, sourcePosition, targetPosition, data, ...props }: any) => {
const [targetArray, setTargetArray] = useState<any>([])
const add = (type: string) => {
let tmp = type + (targetArray.length + 1)
setTargetArray([...targetArray, tmp])
}
return (
<>
{targetArray && targetArray.map((id: string, key: any) => (
<Handle
key={key}
type="target"
position={targetPosition ? targetPosition : Position.Left}
id={id}
style={{ background: '#555' }}
isConnectable={isConnectable}
/>
))}
<div style={{ display: "flex", justifyContent: "space-around", alignItems: "center" }}>
<div style={{ flex: 1 }}>
<ButtonGroup
orientation="vertical"
aria-label="vertical outlined button group"
size="small"
>
<Button key="targetMore" onClick={() => add("T")}>+</Button>
</ButtonGroup>
</div>
<div style={{ flex: 2 }}>
<div style={{ fontWeight: 500, fontSize: 15 }}>{data.label}</div>
</div>
</>
);
});
export default IncNode
I simplified the code by removing the icons, the less function, and the buttons on the right. When I try to connect the first connection ring I have this error :
The above error occurred in the <ConnectionLine> component:
at ConnectionLine
cjs.js:12 Uncaught TypeError: Cannot read properties of null (reading 'find')
at ConnectionLine (cjs.js:12)
How can I increase my number of connection rings, and that they work when I want to connect them ?
Thank you in advance for your answers
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
How can my custom node have dynamic number of outputs?
Hi all. I have tried searching and looking through node-red function and switch nodes but cant pin down how I can have 1...
Read more ><Handle /> API - React Flow
Dynamic Handles . If you are programmatically changing the position or number of handles in your custom node, you need to update the...
Read more >How to get the source and target handles in React Flow 10
As we use custom nodes we can easily derive the number of outgoing handles for each node from our own custom node properties...
Read more >How to add different number of port dynamically to node ...
Right, true, true), makePort("B", go.Spot.Bottom, true, false), { // handle mouse enter/leave events to show/hide the ports // mouseEnter: ...
Read more >Use Dynamic Entities for Customized Interactions | Alexa ...
You can also include more than one slot type, but the total number of dynamic entities, including synonyms, for all slot types should...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Hi @moklick !
Thanks for your response, it’s awesome! She solves everything!
So I did :
Thank you for the documentation, although I looked for it in the issues, I had not found it.
But thanks to the word “updateNodeInternals” I found this issue (1038) which solves my problem as well …
Thanks again, and keep it up, ReactFlow is awesome.
Hey @Ipicky22
whenever you update the handles programatically you need to use the
useUpdateNodeInternalshook to inform ReactFlow about the changes you made https://reactflow.dev/docs/api/hooks/#useupdatenodeinternalsIn your component: