Skip to content

Instantly share code, notes, and snippets.

@webdesignberlin
Forked from emilong/jsx-object-literal.jsx
Created October 16, 2016 20:18
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 webdesignberlin/a0d5b1cf362a90431e9ec62e513aaea8 to your computer and use it in GitHub Desktop.
Save webdesignberlin/a0d5b1cf362a90431e9ec62e513aaea8 to your computer and use it in GitHub Desktop.
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 }} />;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment