简体   繁体   中英

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!

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM