Created
October 20, 2016 22:05
-
-
Save jjsub/e531be314aad7a0164389f6bf9af7309 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
With JSX | |
Ok, so this is not properly ES6, but you can use some ES6 features like property value shorthand very conveniently with JSX spread/rest syntax. | |
function WhySoManyProps(props) { | |
const user = extractUser(props); | |
const fudge = calculateFudge(); | |
const bits = computeBits(); | |
// This is soooooo redundant. | |
return <SomeComponent user={user} fudge={fudge} bits={bits} />; | |
} | |
function Shorthand(props) { | |
const user = extractUser(props); | |
const fudge = calculateFudge(); | |
const bits = computeBits(); | |
// spread all the new props which have the exact same name as the props | |
// for the child component using ES6 syntax. | |
return <SomeComponent {...{ user, fudge, bits }} />; | |
} | |
//from https://engineering.haus.com/dumb-es6-tricks-53ecadd1b29f#.l4f8xif5b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment