ReactJS

How to write the first program in Reactjs?

How to write the first program in Reactjs?
How to write the first program in Reactjs?

In this reactjs tutorial for beginners we learn how to write the first program in react js and make the first file also.

Open your project in visual studio code and run the command npm start.

OR

Open your project using cmd follow the bellow steps. (refer the below image for your reference).

  • C:\Users\user>cd project
  • C:\Users\user\project>cd blog
  • C:\Users\user\project\blog>npm start
how to run the project in reactjs
how to run the project in reactjs

Make New File (refer the below image for your reference).

  1. Right Click on src folder and click on New File to create your first file.
  2. Give the file name for your page like (Login.js) keep the first latter as capitalize.
  3. Wright below code in your file (Login.js).
function Login () {
    return (
        <div className="App">
            <h1>Hello World</h1>
        </div>
    );
}
export default Login;
Make the first file in Reactjs
Make the first file in Reactjs
  1. Open Index.js file and import or replace default ‘./App’ file name to your file name ‘/Login’.
  2. Same as in render function, just add or replace <App /> tag to your file name tag <Login />.
Reactjs index.js file
Reactjs index.js file

Runs the app in the development mode.

Open http://localhost:3000 to view it in the browser.

Reactjs output
Reactjs output in browser

Getting Started with Create React App. This project was bootstrapped with Create React App.

Open your project in visual studio code using shortcut (code .) in command prompt

C:\Users\user\project\blog>code .