Lawrence Vo
Lawrence Vo

Reputation: 187

What is ...props in React?

For instance, the code in Facebook's data table uses ...props. Can someone explain to me what it is and how it's used? I'm sure it's related to this.props but I'm not entirely sure. Thanks!

Upvotes: 1

Views: 143

Answers (2)

Ale
Ale

Reputation: 447

https://facebook.github.io/react/docs/jsx-spread.html

What's with the weird ... notation?

The ... operator (or spread operator) is already supported for arrays in ES6. There is also an ECMAScript proposal for Object Rest and Spread Properties. We're taking advantage of these supported and developing standards in order to provide a cleaner syntax in JSX.

Upvotes: 6

Alex Harris
Alex Harris

Reputation: 6392

It is spread syntax. This allows all of this.props to be passed to the component. The spread operator syntax is new to ES6.

Facebook's site has information regarding this here.

The properties of the object that you pass in are copied onto the component's props.

You can use this multiple times or combine it with other attributes. The specification order is important. Later attributes override previous ones.

Upvotes: 0

Related Questions