Dev Teywa

Dev Teywa

  • NA
  • 250
  • 40.3k

How to pass props optional to children using react.CloneElement

Aug 8 2021 5:14 AM

Hello guys,

I have component 1 contain props1 and props2 as optional props in component parent i return React.cloneElement contain props

like this

React.cloneElement(children, {
props1:{
... children.props.props1,
Val:'test'
}, 
props2:'test'
}) 

Problem in this component parent show error

Cause it don't have all time children with this props

Error

Unknown event handler property 'props' it will be ignored.

 

Thanks


Answers (1)