Skip to content

Instantly share code, notes, and snippets.

@rrharvey
Last active March 3, 2017 16:01
Show Gist options
  • Save rrharvey/e9c6b87c84c90bcf639ff27ddc3f43e7 to your computer and use it in GitHub Desktop.
Save rrharvey/e9c6b87c84c90bcf639ff27ddc3f43e7 to your computer and use it in GitHub Desktop.
Object spread operator in JSX
const LabelValue = props => <div>{props.label}: {props.value} ({props.note})</div>;
const ComponentOne = props => {
const label = 'Label';
const someValue = 'Value';
const note = 'Lorem ipsum dolor sit amet';
return <LabelValue {...{
label,
value: someValue,
note
}}/>;
};
// is the same as
const ComponentTwo = props => {
const label = 'Label';
const someValue = 'Value';
const note = 'Lorem ipsum dolor sit amet';
return <LabelValue label={label}
value={someValue}
note={note}/>;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment