ReactJS is a UI framework. To learn ReactJS, you don't need nodejs, npm or any other fancy tools. Just a library script file you can insert the library on a simple index.html and start writing javascript. Note because you are writing on web you need two scripts (exactly like you had).
<script src="https://unpkg.com/react@latest/umd/react.development.js" crossorigin="anonymous"></script>
<script src="https://unpkg.com/react-dom@latest/umd/react-dom.development.js" crossorigin="anonymous"></script>
Here is an example 1 with just pure javascript & React:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://unpkg.com/react@latest/umd/react.development.js" crossorigin="anonymous"></script>
<script src="https://unpkg.com/react-dom@latest/umd/react-dom.development.js" crossorigin="anonymous"></script>
</head>
<body>
<div id="root"></div>
<script>
function Hello(props) {
return React.createElement('h1', null, `Hello ${props.text}`);
}
ReactDOM.render(
React.createElement(Hello, {text: 'World'}, null),
document.getElementById('root')
);
</script>
</body>
</html>
If you notice closely, everything in example 1 script is in JavaScript, there isn't html inside the script, just pure javascript in my script. React & ReactDom gets inserted into my window so I can access it globally. Great this will work, I can keep doing this doing this but React introduced a way to insert html into javascript (JSX) so we can write less javascript (we r all lazy developers). So how can we write JSX because browsers doesn't understand JSX and they only understand javascript?
Well we will use a tool called standalone library (babel standalone). It will transpile (converts all the code you wrote into browser readable javascript) all the code you wrote in JSX and javascript into a normal javascript file. Before this process starts, you need to let the standalone library know which javascript files you want to transpile so you attach type="text/babel"
like this <script type="text/babel">....</script>
. Once you dom loaded, standalone library will transpile the scripts you told it to transpile and inserts pure javascript into your dom then your javascript will run.
Yes I said that... 1.First your code will transpile 2. then it loaded into the dom 3. Then my javascript runs. This is exactly why we should never use it in production because of the huge delay that happens before your javascript starts running with reactjs. That is where modern tools will help.
Here is example 2 with JSX & React on browser:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://unpkg.com/react@latest/umd/react.development.js" crossorigin="anonymous"></script>
<script src="https://unpkg.com/react-dom@latest/umd/react-dom.development.js" crossorigin="anonymous"></script>
<script src="https://unpkg.com/babel-standalone@6.26.0/babel.min.js" crossorigin="anonymous"></script>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
function Hello(props) {
return <h1>Hello {props.text}</h1>;
}
ReactDOM.render(
<Hello text="World" />,
document.getElementById('root')
);
</script>
</body>
</html>
Great now that we inserted, JSX, what if I want to use latest ES6 and beyond features? Browsers don't support them yet. The standalone library comes to rescue again. The library gives you ability to add plugins to compile latest javascript or jsx or others into javascript.
Here is example 3 with ES6 and JSX on browser with a plugin:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://unpkg.com/react@latest/umd/react.development.js" crossorigin="anonymous"></script>
<script src="https://unpkg.com/react-dom@latest/umd/react-dom.development.js" crossorigin="anonymous"></script>
<script src="https://unpkg.com/babel-standalone@6.26.0/babel.min.js" crossorigin="anonymous"></script>
</head>
<body>
<div id="root"></div>
<script data-plugins="transform-es2015-modules-umd" type="text/babel">
class Hello extends React.Component {
render() {
return <h1>Hello {this.props.text}</h1>;
}
}
ReactDOM.render(
<Hello text="World" />,
document.getElementById('root')
);
</script>
</body>
</html>
All these tools like babel, webpack, help make your app ready for production but for learning it is much easier first to understand react without extra tools then slowly start expanding.
** Note: All the examples are for learning purposes and prototyping and not for production use, if you read my entire answer you will know why.