React JS
React JS
What is ReactJS?
In ReactJS, JS stands for JavaScript. ReactJS is a library of JavaScript.
It is helped to create UI(frontend).
It is an open source language.
It was developed and managed Facebook. Facebook is also developed on
ReactJS. And all its apps like Instagram, messenger are also developed on
ReactJS.
Features of ReactJS:
1. JSX: It is a combination of JavaScript and HTML. React don’t know
HTML. React knows the JSX.
2. Components: The containers in the web page are known as
components. A web-page is made of multiple components. If we
change any component in web page, then it will only render only that
component.
3. One-way data binding: The data is transfer from Source to
destination. It is one way data binding.
4. Virtual DOM: There are 2 types of DOM, i.e., Virtual DOM & Actual
DOM. In actual DOM, we used methods like
document.getElementById(“id”). When actual DOM is runs in browser,
it creates Virtual DOM. Virtual DOM is render the particular element
which we want to change.
5. Simplicity: The learning phase is very in ReactJS. It is simple to
understand and work.
6. Performance: As reactJS is a lightweight library.
ReactJS Environment Setup
Steps to follow:
Step1: Download Node JS and npm.
Search on google nodejs download
Click on site nodejs.org/en/download/
Then download the latest version.
Install the nodejs as of other applications.
Step2: To check nodejs is properly or not
Click on start and search cmd
Simply type node –v
Then it will show nodejs version
And then for npm simply type npm –v
Then it will show node package manager version
Step3: Install any text editor (visual studio code/ sublime text)
Then in app.css file, remove all the existing classes, simply add following
class.
All the files are imported in index.js file.
The tag named as <App /> in index.js file
This is component. Multiple times will call it, it will print again & again.
The workflow of React App
In this part will know the exact the workflow of react app
The out which is show in the browser which will write in app.js file.
This is one of the component.
Component is a piece of code which can we run/use in repeated action.
In index.js file our component is imported.
All the work is done in import and export manner.
Import & export are advanced javascript keywords.
Simply remove all the classes in app.js file. Then you will see the output as
follow:
Now give new class name to <div> section
App.js is a component.
App.css is component which we export to App.js
App.js is export to index.js
In index.js, by using dom rendering method, we call it to index.html page.
React Components
What are react components?
Components are independent and reusable bits of code.
Components are JavaScript files.
They serve the same purpose as JavaScript functions.
But it works in isolation and returns HTML via render function.
Header
Upper Side
Menu
Middle Article
lower Side
Menu
Footer
Types of Components?
1. Class Based: This components are ES6 class based components.
2. Functional Based: This components are based on JavaScript functions.
Class based component:
Class based component is ES6 class.
We managed states in it.
State is a private object is accessible in the class in which we store
data throughout the execution.
It can received props / arguments which returns JSX
Example:
Let pass props in App.js
Person.js is a child of App.js
To pass props from parent, we have to create user defined attribute.
e.g., name=”John” in App.js
In App.js
What is State in React JS & How to use it?
State is a built-in object of the React Components.
The state object is used to store all the data that belongs to that
particular component only.
The state is only accessible inside the component it belongs to.
State is mutable, it can be changed as per need.
Whenever the state object changes the component is re-rendered.
To use state inside a class component “this.state” is used.
To use state inside a functional component “useState” is used.
Example:
Let’s create state in class component Person.js
In Person.css File;
In App.js File
How to give inline CSS?
Handling the Form Inputs
Create a file named as Form.js in Components folder.
Import this file to App.js
Now simply create a form in Form.js
Index.html file
Footer.js File
Index.html file
App.js File
React Router Package (Setup & use)
Search on google react router
Click on link www.reactrouter.com