Search code examples
javascriptreactjsecmascript-5ecmascript-2017

passing to children all state and props in react


I have the following code on my render:

<TourHeader key="TourHeader" {...this.props, ...this.state} />

I get the following error:

Syntax error: Unexpected token, expected }

Only this was working:

<TourHeader key="TourHeader" {...this.props} />

How do I solve this?


Solution

  • You can spread them separately:

    <TourHeader key="TourHeader" {...this.props} {...this.state} />