DEV Community

Ebn Sina
Ebn Sina

Posted on

How to write React code without create-react-app

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>
Enter fullscreen mode Exit fullscreen mode
  • 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>
Enter fullscreen mode Exit fullscreen mode
  • 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>
Enter fullscreen mode Exit fullscreen mode
  • 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>
Enter fullscreen mode Exit fullscreen mode
  • 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>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)