Last active
March 3, 2017 16:01
-
-
Save rrharvey/e9c6b87c84c90bcf639ff27ddc3f43e7 to your computer and use it in GitHub Desktop.
Object spread operator in JSX
This file contains hidden or 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
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