user2879704
user2879704

Reputation:

RouteHandler attr value has three preceding dots

I am going through a react-router code from here. This is a simpler implementation of reddit posts website.

RouteHandler takes an extra attribute as {...this.state}.

          <div className='content'>
            <RouteHandler {...this.state} />
          </div>

What does triple dots inside curly braces mean?

this.state is not explicitly assigned a value, what does it get resolved as?

And how does this pick up one of the three route handlers defined in the routes variable here -

Upvotes: 0

Views: 40

Answers (1)

Henrik Andersson
Henrik Andersson

Reputation: 47202

This is ES6 spread operator, what it does is that it unpacks an array into individual parameters that gets sent into the RouteHandler.

While this only works for arrays in ES6, the JSX transformer will allow you to use this syntax for objects as well enabling you to use it on objects such as this.state.

Updated to clarify thanks to @zerkms;

Upvotes: 4

Related Questions