-
Notifications
You must be signed in to change notification settings - Fork 47k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a section about es6 object shorthand #9115
Conversation
Thanks for the PR! Maybe we should link to an external resource, too? |
docs/docs/jsx-in-depth.md
Outdated
myPropsOne: this.props.myPropsOne, | ||
myPropsTow: this.props.myPropsTwo | ||
}; | ||
return ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would just type props manually in the second example.
<MyComponent
myPropsOne={this.myPropsOne}
myPropsTwo={this.myPropsTwo} />
docs/docs/jsx-in-depth.md
Outdated
@@ -245,6 +245,32 @@ function App2() { | |||
|
|||
Spread attributes can be useful when you are building generic containers. However, they can also make your code messy by making it easy to pass a lot of irrelevant props to components that don't care about them. We recommend that you use this syntax sparingly. | |||
|
|||
### ES6 Object Shorthand | |||
|
|||
If you want to filter the props that you want to pass, you can do it by using ES6 Object Shorthand in combination with object spread operator and object destructuring assignment: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please link to MDN.
docs/docs/jsx-in-depth.md
Outdated
If you want to filter the props that you want to pass, you can do it by using ES6 Object Shorthand in combination with object spread operator and object destructuring assignment: | ||
|
||
```js{4} | ||
render(){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: need space before {
docs/docs/jsx-in-depth.md
Outdated
``` | ||
This is roughly equivalent to a code that looks like this: | ||
```js{4} | ||
render(){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: need space before {
docs/docs/jsx-in-depth.md
Outdated
render(){ | ||
const {myPropsOne, myPropsTwo} = this.props; | ||
return ( | ||
<MyComponent {...{myPropsOne, myPropsTwo}} /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use more realistic prop names than myPropsOne
, myPropsTwo
. Maybe onClick
and value
.
Thank you for filing this PR! I'm sorry to be the bearer of bad news, but the documentation and source code for reactjs.org now lives in a different repository: reactjs/reactjs.org. (For more info on why we made this move, see issue #11075.) Would you be willing to re-open this PR on the new repo? I promise we'll review it quickly! |
Not quite sure if the heading should be ES6 Object Shorthand or Filtering Props. Thoughts?