1

I want to add a draggable Rect (red in the screenshot below) with children (the icon and text in the screenshot below). Whenever I try this, I get this error:

TypeError: parentInstance.add is not a function

Here is the code of just trying to add the text:

<Rect x={0} y={0} width={200} height={100} draggable fill="red">              
    <Text text="Pencil" />                                                      
</Rect> 

enter image description here

1 Answers1

1

Rect or another other Konva shape can't have children elements. You can't nest on shape into another shape. For that case, you need to use Groups

<Group x={0} y={0} draggable>
  <Rect width={200} height={100} fill="red" />
  <Text text="Pencil" />                                                      
</Group>
lavrton
  • 18,973
  • 4
  • 30
  • 63
  • Oh AWESOME! Btw, I've memorized your name from the amount of answers you've provided about konva :). This is also a dumb question, but is there a way to put normal React components in a group? –  Dec 22 '20 at 20:56
  • 2
    If you mean DOM components, like `div` then no. – lavrton Dec 22 '20 at 21:12