Hi guys! This is the beginning of another article series. I'm now looking more on Java Script. This new series is about React JS. Let me explain little bit of React JS.
React is a JavaScript library developed at Facebook to facilitate the creation of interactive, stateful & reusable UI components. React is mainly focused on Virtual DOM and State Management.

DOM

Application Programming Interface (API) for valid HTML and well-formed XML documents. It defines the logical structure of documents and the way a document is accessed and manipulated.

Virtual DOM

Virtual DOM is an in memory Javascript object representation of the browser DOM. It’s a lightweight JavaScript object which is copy of Real DOM. React selectively renders sub-trees of nodes in the DOM based upon state changes. When the existing virtual dom is changed, react compare the new virtual DOM with the old virtual DOM and apply the changes occured to the new virtual DOM. Then update the real DOM in browser according to the differences. Do not render the whole DOM.

Components

React components are small, reusable pieces of code that return a React element to be rendered to the page. In the following picture, numbered sections are individual components. When we use React JS, UI is fully created using these components.


State

State means simply, the place/store where data of a component is directly saved. This data can be passed to other components as props. State is managed by the component itself. A component cannot change its props, but it can change its state. To do so, it must call this.setState(). Only components defined as classes can have state(Class components). The component which don't have state are called as Functional components.

Props

Usually component has some data. In React we have Parent components Child components. Props are mainly used to pass data from Parent to Child. Later we'll see the way to do it. 

How to install React JS?

You have to install Node JS first, before going for React JS installation. Following command will install React JS globally in your computer(In Linux).
sudo npm install -g create-react-app

How to create a React JS project?

After installing react js, go into the folder where you want to build a project. Then use the below command to create a new project. Ii will create a new folder with the name you provide. Last parameter is the name you provide.
create-react-app TestProject

LET'S BUILD A SIMPLE FRONT-END APPLICATION

I'm going to create an application which takes your height and weight and return the BMI value with the health status.



So we have to create a project folder first. This will include all the React project files generated by the CLI.
create-react-app bmi-calculator

index.html
Find the file in the folder called index.html. Then place this code.


App.css
Find the file in the folder called App.css. Then place this code. This will be responsible for styling.


Usually App.js file is the main JS file invoked after bootstrapping the index.js file. Then the structure in this file will be rendered accordingly. This is the Most Parent component in any React JS component. Data included in the state of this App component can be passed to a parent component. In this project, BmiCalculator is a child of App. In state of App component, I have put the title for the application. State object contains item called title. Then we can pass the title to the BmiCalculator component as a prop. This prop can be accessed in the the Child class; In this case, BmiCalculator  is the child.
{ this.state.title }

App.js

You will get errors since you have not created the components called Navbar and BmiCalculator. So create a folder called components in the src folder.
There are only 4 components in this folder.
  1. BmiCalculator
  2. Navbar
  3. Form
  4. Result

Create another folder called assets to store our assets like images. You can put any image in it to be displayed in the UI like the picture above. We will include all the other components in this folder. Now create two new JS files called BmiCalculator.js and Navbar.js. Look at the code below.

Navbar.js
This is the top most component in the UI of the application. Get this code!


BmiCalculator.js

We can access the prop passed in App.js file.  How to print it? Use this code.
{ this.props.title }

Form.js
Form.js is the most important component. It takes the inputs and triggers some events. When we use Events in React, we must bind them before using. Where to bind them? Constructor is the best place for it. handleWeightChange and handleHeightChange are the two events to handle the inputs. After clicking the Get BMI button, getBMI method will be called. When the bmi value in the state is not zero, Result component will be loaded to the DOM. getBMI  method has the logic to decide the health status according to the value of BMI.


Now we have completed our front-end application. You can see a demo from here.
https://bmi-calculator-react.herokuapp.com/

Source Code : https://github.com/SalithaUCSC/BMI-Calculator

I think you could get some basic knowledge in React JS. Download the project and hit npm install to install the missing dependencies. Then hit npm start to run the project. Then it will start in your web browser. Observe this project. This is an ideal project to understand React components, state, props and event handling in a much easier way. I hope you will do it..
More React JS articles will be published soon.

Good Bye guys!


63 Comments

  1. Good Post and informative. Thank you so much for sharing this good post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
    React JS Training in Electronic City

    ReplyDelete
  2. Nice Blog ..
    Thanks for discussing the basics concepts . This will also help in reactjs web development services also . Thanks for sharing this information .

    ReplyDelete
  3. If you are looking for the Reactjs development companies , So here is the list of Top 10 ReactJS Development Companies. Thanks for the post .

    ReplyDelete
  4. Thanks for sharing the valuable information.
    Full Stack Online Training

    ReplyDelete
  5. Thanks for discussing the basics concepts . This will also help in reactjs web development services also . Thanks for sharing this information .

    ReplyDelete
  6. Nice blog..! I really loved reading through this article. Thanks for sharing.
    React JS training in hyderabad

    ReplyDelete
  7. Congratulation for the great post. Those who come to read your Information will find lots of helpful and informative tips. Reactjs Tutorials Online

    ReplyDelete
  8. Here is my favourite BMI calculator. This calculator help you in calculating your health and fitness.

    ReplyDelete
  9. Here is my favourite BMI calculator. This calculator help you in calculating your health and fitness.

    ReplyDelete
  10. Thank you for the feedback :D I didn't get you..what did you mean?

    ReplyDelete
  11. This comment has been removed by the author.

    ReplyDelete
  12. Here are the Top Mobile App Development Companies New York which produce excellent app development services along with additional services and resources that support any business demands.

    ReplyDelete
  13. Great work done by author of this blog. Its an Amazing blogger. We are one of the Best ReactJS Development Company in USA Thanks for Information.

    ReplyDelete
  14. Thank you for your feedback Mern Stack :D

    ReplyDelete
  15. This was really a informative Blog. It will be very much helpful to the Developers for Development Process. Here it is clearly explained about React JS Concepts. The Sample code which is given is really useful and the Diagram which is mentioned under Virtual DOM is really easy to understand for Beginners.If you have any questions regarding React Native Framework reach Way2Smile SolutionsWeb App Development Company in Chennai

    ReplyDelete
  16. Great Content. It will useful for knowledge seekers. Keep sharing your knowledge through this kind of article.
    React JS Training in Chennai
    React JS course in Chennai

    ReplyDelete
  17. Its Really Great .This is Excellent Information For Begineers Keep Doing Us.
    I would also Add React Native App Development Services

    ReplyDelete
  18. Thanks for teaching us basics of React JS .
    I hope you will keep it up.

    ReplyDelete
  19. This comment has been removed by the author.

    ReplyDelete
  20. This comment has been removed by the author.

    ReplyDelete
  21. Nice Information provided in the blog!! CodersNews compiled a list
    of Top 5 React Native App Development Companies who have expertise in creating functionality-rich, feature-loaded, and scalable React native mobile applications to let your business portable on mobile.

    ReplyDelete
  22. Thank you for your informative post about React Js Development Services. The information was very helpful. I appreciate you taking the time to share your knowledge with us.

    ReplyDelete
  23. Having followed your post for the past few days, I got a lot of useful information from it. I recently took the react native course and searched for new information. It really helped me gain knowledge. Thanks for sharing your post.

    ReplyDelete
  24. Thanks for sharing this informative article on React JS Basic Concepts. If you want to Hire MERN Stack Developer for your project. Please visit us.

    ReplyDelete

  25. Nice post i will read it again it contains most helpfull information for me thanks.
    Web Design and Development Services
    Mobile App Development Services

    ReplyDelete
  26. stunning post to clear the react js development concepts it is really helpful to get the knowledge . visit our website to know more about react js development.

    ReplyDelete
  27. Nice idea got from your blog. Thanks for that. React JS

    ReplyDelete
  28. While prior programming experience can be beneficial, it’s not a strict requirement. Basic knowledge of HTML, CSS, and JavaScript will be helpful as React builds upon these fundamentals.

    ReplyDelete
  29. Exciting start to a new series exploring into ReactJS! Explore the fundamentals of this advanced JavaScript library, which focuses on Virtual DOM and State Management. Need React development services? Check out Infowind.

    ReplyDelete
  30. This comment has been removed by the author.

    ReplyDelete
  31. This comment has been removed by the author.

    ReplyDelete
  32. I got a great idea from your blog. Thanks for sharing it!

    ReplyDelete
  33. The article is clear, to the point and provides helpful information

    ReplyDelete