Last active
June 26, 2017 03:29
-
-
Save DylanPiercey/03df788203bd9646837561b91720a0d4 to your computer and use it in GitHub Desktop.
JSX Example
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
// 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