5

I would like to know if it is posible to add a new prop to a component instance, the component instance look like this:

enter image description here

Maybe is a bad practice modifying a component instance directly, but I wonder if it is possible or not.

gabrielAnzaldo
  • 3,014
  • 4
  • 19
  • 19

1 Answers1

6

You can do this by using React.cloneElement:

const changeProp = (component) => (
  {React.cloneElement(component, {
    someProp: { value }
  })}
)

Reference to react docs: https://reactjs.org/docs/react-api.html#cloneelement

Ronan Boiteau
  • 9,608
  • 6
  • 34
  • 56
kirecligol
  • 848
  • 7
  • 12