You should start your project with Create React App (CRA).
It's a React app initializer made by the React team. It makes all the setup for you (including Babel and Webpack configurations) and add some really nice features to your development environment.
If you don't want to use CRA, you will need to install:
babel-corebabel-preset-envbabel-preset-react
Then create a file .babelrc in the root of your project containing:
{ "presets": ["env", "react"] }
Then install and configure Webpack to run the Babel transforms.
(Or you could also run Babel manually with babel-cli).
The React documentation slightly addresses the Babel setup problem here.
They also suggest to use CRA here.
Answer from GG. on Stack OverflowYou should start your project with Create React App (CRA).
It's a React app initializer made by the React team. It makes all the setup for you (including Babel and Webpack configurations) and add some really nice features to your development environment.
If you don't want to use CRA, you will need to install:
babel-corebabel-preset-envbabel-preset-react
Then create a file .babelrc in the root of your project containing:
{ "presets": ["env", "react"] }
Then install and configure Webpack to run the Babel transforms.
(Or you could also run Babel manually with babel-cli).
The React documentation slightly addresses the Babel setup problem here.
They also suggest to use CRA here.
Ah, I found an answer in a Beginner's Guide to React at https://egghead.io/courses/the-beginner-s-guide-to-reactjs.
Apparently there is a standalone Babel compiler you can just link to in the head of the document, along with the links to ReactJS and it "does the right thing". Yay! Here are the links I'm using:
<script src="https://unpkg.com/[email protected]/umd/react.production.min.js"></script>
<script src="https://unpkg.com/[email protected]/umd/react-dom.production.min.js"></script>
<script src="https://unpkg.com/[email protected]/babel.min.js"></script>
In the script tag that contains the ReactJS and JSX code, you must use type=text/babel:
<script type="text/babel">...</script>
I hope this helps other people starting out with React and JSX.
I'm guessing I'll eventually need to learn how to use NPM, NPX, Node, Webpack, and Babel (and possibly other tools) to run production ReactJS code, but for now I'm hoping this will allow me to learn ReactJS without having to worry about all that.
Hi, I'm new to web development.
I can't wrap my head around what exactly ReactDOM does. If Babel writes plain JavaScript shouldn't that be enough for browser to render the webpage?
» npm install @babel/plugin-transform-react-jsx-development
» npm install babel-plugin-jsx-control-statements
» npm install @babel/plugin-transform-react-jsx