Skip to content

Instantly share code, notes, and snippets.

@jjsub
Created October 20, 2016 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jjsub/e531be314aad7a0164389f6bf9af7309 to your computer and use it in GitHub Desktop.
Save jjsub/e531be314aad7a0164389f6bf9af7309 to your computer and use it in GitHub Desktop.
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