简体   繁体   English

什么是…React中的道具?

[英]What is …props in React?

For instance, the code in Facebook's data table uses ...props . 例如, Facebook数据表中的代码使用...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. 我确定它与this.props有关,但我不确定。 Thanks! 谢谢!

https://facebook.github.io/react/docs/jsx-spread.html 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. ES6中的数组已经支持...运算符(或散布运算符)。 There is also an ECMAScript proposal for Object Rest and Spread Properties. 还有一个ECMAScript建议书,涉及对象剩余和传播属性。 We're taking advantage of these supported and developing standards in order to provide a cleaner syntax in JSX. 我们利用这些受支持和正在开发的标准,以便在JSX中提供更简洁的语法。

It is spread syntax . 这是传播语法 This allows all of this.props to be passed to the component. 这允许将所有this.props传递给组件。 The spread operator syntax is new to ES6. 扩展运算符语法是ES6的新增功能。

Facebook's site has information regarding this here . Facebook网站在此处提供有关此信息

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. 后来的属性将覆盖先前的属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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