Last active
August 29, 2015 14:23
-
-
Save dlmanning/d1bc66b50e694d8ebe82 to your computer and use it in GitHub Desktop.
Why doesn't the spread operator work in JSX?
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
import { default as React, Component } from 'react'; | |
function makeElements () { | |
return [ | |
<h1>Hello</h1>, | |
<h1>World,</h1>, | |
<h1>How</h1>, | |
<h1>are</h1>, | |
<h1>you?</h1> | |
] | |
} | |
class App extends Component { | |
render () { | |
return <div>{...makeElements()}</div> | |
} | |
} | |
var output = React.renderToString(<App/>) | |
console.log(output); | |
/* Results in a syntax error: | |
SyntaxError: /Users/david/node/spread/spread.js: Unexpected token (15:17) | |
13 | class App extends Component { | |
14 | render () { | |
> 15 | return <div>{...makeElements()}</div> | |
| ^ | |
16 | } | |
17 | } | |
18 | | |
*/ |
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
import { default as React, Component } from 'react'; | |
function makeElements () { | |
return [ | |
<h1>Hello</h1>, | |
<h1>World,</h1>, | |
<h1>How</h1>, | |
<h1>are</h1>, | |
<h1>you?</h1> | |
] | |
} | |
class App extends Component { | |
render () { | |
return React.createElement('div', ...makeElements()); | |
} | |
} | |
var output = React.renderToString(<App/>) | |
console.log(output); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment