I want to play around with React for a little thing. For that first I thought to create a react app with create-react-app then I realize do I really need such a build tool! Then I discover something to play with react without any tool.
please note don't use it in production
- First create a html file called index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>React without create-react-app</title>
</head>
<body>
</body>
</html>
- add root div as react needs to render
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
+ <div id="root"></div>
</body>
</html>
- Then add 3 scripts tag to work with react
<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
- voila! write your react code within tag make sure the script tag have type of text/babel
<script type="text/babel">
function Welcome() {
return <h1>Hello React World!</h1>;
}
ReactDOM.render(<Welcome/>, document.getElementById('root'));
</script>
- Final code will be like this
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="root"></div>
<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<script type="text/babel">
function Welcome() {
return <h1>Hello React World!</h1>;
}
ReactDOM.render(<Welcome/>, document.getElementById('root'));
</script>
</body>
</html>
Top comments (0)