Last active
December 12, 2016 21:57
-
-
Save kevinwucodes/fa105bb1373eca7b415c1fbb46cad595 to your computer and use it in GitHub Desktop.
react components prop spread operator sandbox
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
//http://www.webpackbin.com/NkMEv-_7M | |
import React from 'react'; | |
import {render} from 'react-dom'; | |
import HelloWorld from './HelloWorld.js'; | |
const divContainer = document.querySelector('#app') | |
const obj1 = { | |
first: 'kevin' | |
} | |
const obj2 = { | |
last: 'smith' | |
} | |
const obj3 = { | |
color: 'blue', | |
shape: 'circle' | |
} | |
const obj4 = { | |
shape: 'square', | |
hammer: 'nail' | |
} | |
const theComponent1 = <HelloWorld {...obj1} {...obj2} ></HelloWorld> | |
const theComponent2 = <HelloWorld {...{...obj1, ...obj2}} ></HelloWorld> | |
//const theComponent3 = <HelloWorld {...obj1, ...obj2 } ></HelloWorld> | |
//const theComponent4 = <HelloWorld {{...obj1, ...obj2 }} ></HelloWorld> | |
const theComponent5 = <HelloWorld {...{obj1, obj2}} ></HelloWorld> | |
render(theComponent5, divContainer); | |
/* | |
*** CASE 1 | |
{ | |
first: "kevin", | |
last: "smith" | |
} | |
*** CASE 2 | |
{ | |
first: "kevin", | |
last: "smith" | |
} | |
*** CASE 3 | |
(error) - this doesn't work due to parsing error | |
*** CASE 4 | |
(error) - this doesn't work due to parsing error | |
*** CASE 5 | |
{ | |
obj1: { | |
first: "kevin" | |
}, | |
obj2: { | |
last: "smith" | |
} | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment