Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

viankakrisna
Copy link

Not quite sure if the heading should be ES6 Object Shorthand or Filtering Props. Thoughts?

@acdlite
Copy link
Collaborator

acdlite commented Mar 6, 2017

Thanks for the PR! Maybe we should link to an external resource, too?

@viankakrisna
Copy link
Author

myPropsOne: this.props.myPropsOne,
myPropsTow: this.props.myPropsTwo
};
return (
Copy link
Collaborator

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} />

@@ -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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please link to MDN.

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(){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: need space before {

```
This is roughly equivalent to a code that looks like this:
```js{4}
render(){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: need space before {

render(){
const {myPropsOne, myPropsTwo} = this.props;
return (
<MyComponent {...{myPropsOne, myPropsTwo}} />
Copy link
Collaborator

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.

@bvaughn
Copy link
Contributor

bvaughn commented Oct 8, 2017

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!

@bvaughn bvaughn closed this Oct 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants