Skip to content

Instantly share code, notes, and snippets.

@bikallem
Last active April 28, 2019 20:51
Show Gist options
  • Save bikallem/c2dfe046b63eafd9a859de946d0a56be to your computer and use it in GitHub Desktop.
Save bikallem/c2dfe046b63eafd9a859de946d0a56be to your computer and use it in GitHub Desktop.
React.JS without webpack
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script crossorigin src="http://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="http://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script crossorigin src="http://unpkg.com/@babel/standalone/babel.min.js"></script>
</head>
<body>
<div id="root1"></div>
<div id="root2"></div>
<div id="root3"></div>
<script type="text/babel">
//Various ways of creating React component.
const HelloWorld = ({name}) => <h1>Hello, {name}!</h1>
const HelloWorld2 = ({name, surname}) => React.createElement('h1', null, `Hello again, ${name} ${surname}!`)
const e = React.createElement
const HelloWorld3 = ({name}) => e('div', null, e('p', null, `Hello ${name}!`))
// Various ways of instantiating React component.
ReactDOM.render(
<HelloWorld name="Bikal"/>,
document.getElementById('root1')
);
// All of the following are equivalent
ReactDOM.render(
<HelloWorld2 name="Bikal" surname="Gurung"/>,
document.getElementById('root2')
);
ReactDOM.render(
<HelloWorld3 name="James Bond"/>,
document.getElementById("root3")
);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment