First ReactJs App setup and run - Hello World in ReactJs

Introduction:

ReactJs is a widely popular open source library initiated by Facebook which is used to develop Single Page Application.

React is a Library not a framework, it does not provide complete solution. It is responsible only for handling user interfaces or building front end application and it does it very well.




Setting up ReactJs in the local: 🚀

1. Install Node (we basically need npm and along with npm, npx comes pre bundled.).
        https://nodejs.org/en/download/
        (Download LTS version)

2. Create reactJs App by using create-react-app,
    referencehttps://github.com/facebook/create-react-app

       type it in your terminal to create ReactJs App,
npx create-react-app react-js-hello-world
React app successfully create.

Your ReactApp is successfully created! 😊

3. With the help of create-react-app tool, we are able to create basic react working template for quick development. Generated ReactJs app looks something like this,


generated project structure with create-react-app tool


4. Complete folder structure looks something like this,

expanded view of complete generated folder structure

5. Now I am removing all the unnecessary files and codes from all the files which we do not really need as of now, we will be focusing on the code which is relevant to us and will try to understand the wiring, how ReactJs actually works, 👍🏻

If you notice in line number 6, I introduced <h1> tag and printed a label. Do not worry I will make you understand how exactly html tags are working inside a JS function in sometime,

Modify header component in App.js file and display hello world!

6. Okay! now try to run our very first ReactJs App. 😄 by using following command,
npm start
server got started successfully with npm start command.

Server got started successfully at http://localhost:3000 ✌🏻


Hello world text display in the browser at http://localhost:3000
Woohoo! provided header is printed.


How ReactJs App is working ?

In this section will be trying to understand 2 concepts,
  1. Virtual DOM
  2. JSX
First look at this static html file named as index.html, notice here we have empty <div> element which contains the id attribute which value is root. This <div> element is serving a great purpose here, basically React uses it as a container for dumping all the dynamically generated html from the JS,
Did not understand? 🤔 let me introduce complete wiring then it will make sense 🤓

   index.html

index.html markup


Now in the App.js file, inside App() function, you are seeing html elements, actually these are not actual html elements. It looks like html elements though, this is the magic of ReactJs through which you are able to write html markup inside a JS function which has a great advantage (hint: It makes updation very efficient in the DOM tree). 😄

Actually this is virtual DOM not the real html DOM provided by JSX (JavaScript XML), so JSX enables users to write the html script in react.

This is just to understand that what is going on behind the scene, as an end user it is just like using html markup, all the complexities are abstracted from end user by React.

   App.js

App.js code

      

eventually this above JSX will be parsed to JS code, something like this,
React.createElement("div", {className: "App"},
      React.createElement("h1", null, "Hello World! this is my first React Js Application! 🚀")
)

Okay! now index.js is handling the actual rendering of the DOM, it decides where exactly the JSX of App component need to be rendered.

    index.js

index.js code


If you remember in the index.html, we created empty <div> having the "root" id, we are giving its reference as a second argument of render() function so that provided React component would be dumped or rendered in the html file dynamically and when users load the browser index.html will be displayed with dynamically loaded React component.


Meme: It doesn't matter where you are, I will find you and render you



Alright guys, so this is the basic understanding on ReactJs to start development in React app.
.
.
.

Thank you for reading!
🙋🏻‍♂️

Hemant Singh Bisht

With over 9 years of software development experience, I've dedicated my career to creating scalable cloud solutions for B2B and B2C. Currently, I am leading a Scrum team of highly efficient engineers. As a Full Stack developer, I possess a comprehensive skill set spanning both front-end and back-end technologies. My strong foundation in software engineering and extensive hands-on experience equip me with a diverse skill set covering the entire software development lifecycle. From Epics Grooming to Release and beyond, I take pride in designing and delivering high-quality solutions that meet business objectives. Collaborating closely with cross-functional teams and stakeholders. One of my key strengths is successfully delivering epics from design to deployment, consistently meeting deadlines, and exceeding customer expectations. I am passionate about leveraging technology to create meaningful change and continually seek opportunities to apply my skills to projects that have a positive societal impact.

5 Comments

  1. I found this one pretty fascinating and it should go into my collection. Very good work! I am Impressed.
    Hire Dedicated ReactJs Developers

    ReplyDelete
  2. Thanks for making such a great and valuable blog. You did splendid work for those who were looking for useful information like this. Keep giving your best suggestion for us.

    ENT Expert Faizabad

    ReplyDelete
  3. You are doing a lot of charitable work because of you, people can get the knowledge about this and can understand very easily. Your work is commendable. It's really helpful to all. Thanks for sharing your hard work in the form of our benefits.

    Best Audiologist Doctor in Lucknow

    ReplyDelete
  4. Firstly l am so thankful to you. You are doing such great work for us. you are really rendering service to those who are really needed it .by giving a lot of important information in less time. Thanks a lot for sharing your extravagant precious knowledge with us.

    Best ENT Surgeon in Gurdaspur

    ReplyDelete
  5. You are well equipped with your intelligence and know how to impart knowledge to others. Your way of explanation is very easy to understand. Keep doing like this and thanks for sharing your efforts in the form of our benefits.

    ENT Expert Faizabad

    ReplyDelete
Previous Post Next Post