React JS Basic Concepts
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.
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.
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
{ 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.
There are only 4 components in this folder.
- BmiCalculator
- Navbar
- Form
- 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.
{ 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!
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!
65 Comments
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.
ReplyDeleteReact JS Training in Electronic City
Thank You Ajish! Keep in touch with TechPool
DeleteNice Blog ..
ReplyDeleteThanks for discussing the basics concepts . This will also help in reactjs web development services also . Thanks for sharing this information .
Thanx Hemant!
DeleteAwesome Post Thanks for sharing this blog. Keep on sharing
ReplyDeleteFull Stack online Training
Full Stack Training
Full Stack Developer Online Training
Full Stack Training in Hyderabad
Full Stack Training in Ameerpet
Full Stack Training Institute
Thank You!
DeleteIf you are looking for the Reactjs development companies , So here is the list of Top 10 ReactJS Development Companies. Thanks for the post .
ReplyDeleteThanks for sharing the valuable information.
ReplyDeleteFull Stack Online Training
Thank you for sharing and nice blog
ReplyDeleteReact Js Training
React Js Online Training
React Js Training in Ameerpet
Thank You!
DeleteThanks for discussing the basics concepts . This will also help in reactjs web development services also . Thanks for sharing this information .
ReplyDeleteNice blog..! I really loved reading through this article. Thanks for sharing.
ReplyDeleteReact JS training in hyderabad
Thank you very mcuh!
DeleteCongratulation for the great post. Those who come to read your Information will find lots of helpful and informative tips. Reactjs Tutorials Online
ReplyDeleteThank you for the feedback again :D
DeleteHere is my favourite BMI calculator. This calculator help you in calculating your health and fitness.
ReplyDeleteThank you
DeleteHere is my favourite BMI calculator. This calculator help you in calculating your health and fitness.
ReplyDeleteThank you again!
DeleteThank you for the feedback :D
ReplyDeleteThank you for the feedback :D I didn't get you..what did you mean?
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteHere 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.
ReplyDeleteGreat 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.
ReplyDeleteThank You for the feedback :D
DeleteThank you so much for sharing such an awesome blog...
ReplyDeletebest software company
best IT services company in hyd
mobile development company
mobile application development
best software company hyd
best IT services company in hyd
Thank You for the feedback :D
DeleteThank You for the feedback :D
ReplyDeleteGreat post.
ReplyDeletehttps://forums.perforce.com/index.php?/user/13732-salimahsadadantar/
Thank you :D
DeleteThank you for your feedback Mern Stack :D
ReplyDeleteThis 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
ReplyDeleteThank you!
DeleteNice to hear....Thank You!
ReplyDeleteGreat post.
ReplyDeletehttp://ortelia.com/Forums/member.php?action=profile&uid=72276
glad to hear
DeleteGreat Content. It will useful for knowledge seekers. Keep sharing your knowledge through this kind of article.
ReplyDeleteReact JS Training in Chennai
React JS course in Chennai
glad to hear
Deleteglad to hear
ReplyDeleteIts Really Great .This is Excellent Information For Begineers Keep Doing Us.
ReplyDeleteI would also Add React Native App Development Services
Thanks for teaching us basics of React JS .
ReplyDeleteI hope you will keep it up.
This comment has been removed by the author.
ReplyDeleteThanks for providing this helpful information. I was impressed.
ReplyDeletebulk sms marketing chennai
bulk sms service chennai
promotional sms chennai
sms marketing chennai
sms service provider in Chennai
bulk whatsapp service provider in chennai
bulk sms marketing in chennai
bulk sms price in chennai
bulk sms provider chennai
bulk sms service provider in chennai
chennai bulk sms
best bulk sms service provider in chennai
bulksms in Chennai
This comment has been removed by the author.
ReplyDeleteA really good post, very thankful and hopeful that you will write many more posts like this one.
ReplyDeleteMobile app development company in chennai
Mobile Application Development companies in chennai
Android development companies in chennai
Nice Information provided in the blog!! CodersNews compiled a list
ReplyDeleteof 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.
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.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteHaving 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.
ReplyDeleteReally awesome article
ReplyDeleteReact vs React Native
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
ReplyDeleteNice post i will read it again it contains most helpfull information for me thanks.
Web Design and Development Services
Mobile App Development Services
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.
ReplyDeleteNice idea got from your blog. Thanks for that. React JS
ReplyDeleteTHANKS FOR VALUABLE INFO
ReplyDeleteGCP DATA ENGINEER TRAINING
thanks for sheering information
ReplyDeletenice blog
thank for sharing
ReplyDeleteWhile 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.
ReplyDeleteExciting 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.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteI got a great idea from your blog. Thanks for sharing it!
ReplyDeleteThe article is clear, to the point and provides helpful information
ReplyDeleteT10 Exchange offers seamless online gaming and sports exchange experiences. With a user-friendly interface, diverse game options, secure transactions, and 24/7 customer support, it’s the go-to platform for enthusiasts. Explore innovative features and join a trusted community to enhance your gaming journey.
ReplyDeleteThanks for sharing this valuable information with us.
ReplyDeleteIf you are looking for react js development then you should visit here.