I’m just getting started with React and trying to build my first simple project. I’ve seen two different approaches and I’m confused about which one to use.
First approach using Node.js:
const React = require('react');
const ReactDOM = require('react-dom');
const myComponent = React.createElement('div', { className: 'main-content' }, 'Hello React World');
ReactDOM.render(myComponent, document.getElementById('app-container'));
<!DOCTYPE html>
<html>
<head>
<title>React App</title>
</head>
<body>
<div id="app-container"></div>
<script src="bundle.js"></script>
</body>
</html>
Second approach with CDN links:
const myElement = React.createElement('div', { className: 'main-content' }, 'Hello React World');
ReactDOM.render(myElement, document.getElementById('app-container'));
<!DOCTYPE html>
<html>
<head>
<title>React App</title>
<script crossorigin src="https://unpkg.com/react@17/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@17/umd/react-dom.development.js"></script>
</head>
<body>
<div id="app-container"></div>
<script src="main.js"></script>
</body>
</html>
The first method needs Node.js installation and package management, while the second just uses CDN. Which approach is better for learning React? Can I skip Node.js completely or will I need it eventually?