Skip to content

Instantly share code, notes, and snippets.

@kevinwucodes
Last active December 12, 2016 21:57
Show Gist options
  • Save kevinwucodes/fa105bb1373eca7b415c1fbb46cad595 to your computer and use it in GitHub Desktop.
Save kevinwucodes/fa105bb1373eca7b415c1fbb46cad595 to your computer and use it in GitHub Desktop.
react components prop spread operator sandbox
//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