Node.js
You can download it from: https://nodejs.org/en/
Create React App
Open your terminal in the directory you would like to create your application. Run this command to create a React application named my-react-app:
OR, you can directly make your application without specifying a name, like this:
In this case, all files will be kept in the current directory.
Note: When choosing folder name, make sure there are no spaces or capital letters because of npm naming restrictions.
Once base application is created, if folder specified you just have to enter the folder. You can use this command to enter:
Then just start up the application with this command:
and you are good to go!
Run and Check
Run the React Application with this command:
A new browser window will pop up, if it does't then go on http://localhost:3000/
. Check if it is showing the same page:
If it's the same page then you are good to go!
Hello World
In this we are just putting <h1>
tag in a div with id 'root'. That's it! In div with id 'root' everything will be rendered. We can also change it from 'root' to something else, as we are just getting an element and putting HTML in it.
For this first you need to navigate to src/App.js
, it will look like:
Whatever you put in return will be rendered as HTML on the page, you can change it like:
Note: Remember to wrap whole return value in an HTML element as you can't return multiple elements but you can return multiple elements in one element.
Page would look like this: