Skip to content

Instantly share code, notes, and snippets.

@DylanPiercey
Last active June 26, 2017 03:29
Show Gist options
  • Save DylanPiercey/03df788203bd9646837561b91720a0d4 to your computer and use it in GitHub Desktop.
Save DylanPiercey/03df788203bd9646837561b91720a0d4 to your computer and use it in GitHub Desktop.
JSX Example
// Create your jsx 'templates'
class NameTag extends React.Component {
render () {
return <div>My Name is {this.props.name}</div>
}
}
// Create the element.
const myNameTag = <NameTag name="Dylan"/>
// Render in the browser.
React.render(myNameTag, document.getElementById('root'))
// Render in the server.
app.get('/home', (req, res) => {
res.end(`
<!doctype html>
<html>
<head>...</head>
<body>
<div id="root">${React.renderToString(myNameTag)}</div>
</body>
</html>
`)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment