If you are new to ReactJS and wish to start learning from the very basics without installing Node.js or using npm packages, you can still set up a basic React environment using just HTML, Babel, and the React and ReactDOM libraries from a Content Delivery Network (CDN). This approach is suitable for beginners who want a quick introduction to React without diving into the complexities of a full development environment.
Step 1: Set Up Your HTML File
Create an HTML file and include the necessary script tags to import React, ReactDOM, and Babel from a CDN.
index.html file code
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Hello React!</title>
<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@6/babel.min.js"></script>
</head>
<body>
<div id="entryPoint"></div>
<script data-plugins="transform-es2015-modules-umd" type="text/babel" src="./Hello.js"></script>
<script data-plugins="transform-es2015-modules-umd" type="text/babel" src="./app.js">
</script>
</body>
</html>
import Hello from './Hello'
class MyComponent extends React.Component {
constructor(props) {
super(props);
// Initialize state if needed
this.state = {
// your state properties here
};
}
// Define your component's render method
render() {
return (
<Hello />
);
}
}
// Render your component to the root element
const rootElement = document.getElementById('entryPoint');
ReactDOM.render(<MyComponent />, rootElement);
class Hello extends React.Component{
render(){
return <div>Hello React!</div>
}
}
Step 4: Open in Browser
Save your HTML file and open it in a web browser. You should see your React component rendering “Hello React!” in the specified div element.
This approach allows you to experiment with React without setting up a complete development environment. As you progress in your learning journey, you may explore more sophisticated setups involving Node.js, npm, and modern build tools for larger and more complex React projects.
You can also download a complete code from my github repository