REACT JS ADONS
1 javascript (ES6) code snippets
2 Live Sass Compiler
3 Live Server
4 ES7+ React/Redux/React-Native snippet
-----------------------------------------------------------
React Library
1) npm install react-bootstrap bootstrap
https://react-bootstrap.netlify.app/docs/components/buttons/
// bootstarp file add this file in index.js
import 'bootstrap/dist/css/bootstrap.min.css';
2) npm install react-router-dom
3) npm install react-axios
install The Postman app in your system
https://www.postman.com/downloads/
4) npm i redux react-redux redux-thunk
-----------------------------------------------------------
youtube link
https://www.youtube.com/watch?v=EHTWMpD6S_0&t=91s
https://www.youtube.com/playlist?list=PL8p2I9GklV47BCAjiCtuV_liN9IwAl8pM
https://www.thapatechnical.com/2021/07/react-js-1702-in-one-video-by-thapa.html
npx = (Node Package Execute)
npm = (Node Package Manager)
-----------------------------------------------------------
section 4:
STATE ===> data ko store karane ka liye
STATE ===> just like a object, we store data in STATE
state update in COMPONETN when we change
jab hum state ko change/update karte hai to component ko pata chal jata hai kuch update ua hai VAR ke kesh me aisa kuch nahi hota
PROPS ===> data ko transfer karne k liye 1 component se 2 component me data bhejne k liye
*************************************************************************
COMPONENTS CREATE
*************************************************************************
1) function components
2) class components
======== App.js page ==============
import Header from './component/header.js'
function App() {
return (
);
}
======== App.js page ==============
1) function components
---------------------------------------------
import '../assets/css/header.css'
function Header() {
return (
HEADER
);
}
export default Header;
2) class components
---------------------------------------------
import {Component } from "react"
class Footer extends Component {
render(){
return (
);
}
}
export default Footer;
*************************************************************************
WHAT IS JSX
*************************************************************************
JSX = js + HTML
let fname = "rakesh"
const my_func =() =>{
return "this is my function value";
}
function JSX(){
let lname = "kumar"
return (
);
}
export default JSX;
section 5:
*************************************************************************
PROPS IN REACT
*************************************************************************
1) Props in function component
2) Props in class component
3) Immutability of props
1) Props in function component
-------------------------------------------
========== app.js page ========
========== component page ========
function Header(props) {
return (
HEADER {props.heanderName}
);
}
2) Props in class component
-------------------------------------------
========== app.js page ========
========== component page ========
class Footer extends Component {
render(){
return (
);
}
}
section 6:
*************************************************************************
STATE IN REACT
*************************************************************************
1) state in function component
2) state in class component
1) state in function component
-------------------------------------------
import {useState} from 'react'
function Header(){
const [LocalVar,setData] = useState("jitender")
function UpdateData(){
setData("SHARMA")
}
return(
HEADER PART
{LocalVar}
);
}
export default Header;
1) (b) state in function component
-------------------------------------------
import {useState} from 'react'
function Header(){
const [LocalVar,setData] = useState(0)
function UpdateData(){
setData(LocalVar + 1)
}
return(
HEADER PART
{LocalVar}
);
}
export default Header;
2) state in class component
-------------------------------------------
import {Component} from "react";
class State extends Component{
constructor(){
super();
this.state = {
counter: 10,
};
}
increment() {
this.setState({
counter: this.state.counter + 1,
});
}
render(){
return (
state class base components {this.state.counter}
);
}
}
*************************************************************************
DESTRUCTURING PROPS
*************************************************************************
1) Destructuring PROPS in function component
-------------------------------------------
function DesturcFuncProps(props) {
const {fname, lname} = props;
return (
DESTRUCTURING FUNC PROPS = {fname} {lname}
);
}
2) Destructuring PROPS in class component
-------------------------------------------
import {Component } from "react"
class DesturcClassProps extends Component {
render(){
const {fname, lname} = this.props;
return (
DESTRUCTURING CLASS PROPS = {fname} {lname}
);
}
}
section 7:
*************************************************************************
HANDLING EVENTS IN FUCTIONAL COMPONENT
*************************************************************************
function EventFuction() {
function clickEventHandal(){
alert("event in function tast complete");
}
return (
EVENT FUNCTION
);
}
*************************************************************************
HANDLING EVENTS IN CLASS COMPONENT
*************************************************************************
import {Component } from "react"
class EventClass extends Component {
clickEventHandal(){
alert("event in Class tast complete");
}
render(){
return (
);
}
}
export default EventBinding;
1 function all
2 jsx
3 props
4 desctuj props
5 event
6 function event
*************************************************************************
IMAGES PATH IN REACT
*************************************************************************
*************************************************************************
INLINE CSS IN REACT
*************************************************************************
Header
*************************************************************************
INLINE BG IMG CSS IN REACT
*************************************************************************
import plusIcon from './images/icons/plus.png';
import minusIcon from './images/icons/minus.png';
*************************************************************************
CSS BACKGROUND IMAGE
*************************************************************************
.lSAction a{background-image: url('../../Components/images/hoteldetail/controls1.png');}
************************************************************************************************************************************************************************
************************************************************************************************************************************************************************
************************************************************************************************************************************************************************
************************************************************************************************************************************************************************
************************************************************************************************************************************************************************
************************************************************************************************************************************************************************
************************************************************************************************************************************************************************
************************************************************************************************************************************************************************
************************************************************************************************************************************************************************
--------------------------------------------------------------------------
https://www.youtube.com/watch?v=GiyL4KFRNBA
--------------------------------------------------------------------------
1) React is javascript library
2) the main focus is building UI as fast as possible
3) Single page application
means complete website is single pages
4) Maintained by facebook
5) Apps with react is
Netflix
Whatsapp web
Instagram
--------------------------------------------------------------------------
REACT PREREQUISITES
--------------------------------------------------------------------------
1) HTML, CSS, JAVASCRIPT
2) ES6 understanding will make you comfortable with reactjs
--------------------------------------------------------------------------
REACT ENVIRONMENT UP WITH WINDOWS
--------------------------------------------------------------------------
Install node and npm
VS code editor
install the CRA app == create react app
links
https://nodejs.org/en
1) install node js
2) cmd type on folder url
3) node -v ===> for version check of node js
4) npm-v ===> for version check of npm
5) cls => for clear cmd
6) create new Project:- E:\ReactExamples>npx create-react-app project2
7) cd project2
8) code . (enter) ===> for project open in vs code
9) npm start ===> for start the project
10) ctrl+c ===> to stop the project
npx = (Node Package Execute)
npm = (Node Package Manager)
--------------------------------------------------------------------------
AFTER OPEN PROJECT OF REACT
--------------------------------------------------------------------------
NPM ===> node package manager
NPM ALTERNATIVE == yarn
node_modules ===> all node package manage here
npm install pakage-name ====> for install any package, and any library
--------------------------------------------------------------------------
package.json file inner ====>
--------------------------------------------------------------------------
MOST IMPORTANT FILE
package.json file ===> hamare project ki detail rakhta hai
project name
react current version show
kon kon se package install hai
--------------------------------------------------------------------------
package-lock.json file inner
--------------------------------------------------------------------------
pakcage.json ====> ki detail rakhata hai full
--------------------------------------------------------------------------
src ===>
--------------------------------------------------------------------------
app.css ===> css
app.js ===> code start of html
app.test.js ===> for developer advance js
index.css ===> for creat css index pages
index.js ===> enter point of react
--------------------------------------------------------------------------
public ===>
--------------------------------------------------------------------------
html related detail store
--------------------------------------------------------------------------
node_modules ===>
--------------------------------------------------------------------------
all package store in this folder
when we tranfer the REACT PROJECT that no need to this in file
----------------------------------------------------------------------------------------------
COMPONENT ===>
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=KV0v78T-fbw&t=207s
A piece of code that can resue
Such as function
But more powerful than function
i) lifecycle
ii) self state
iii) props
iv) parameter defference
v) self HTML
Header, Footer is best example
mostly 2 component
1) function component
2) class component
3) HOC(HIght order component)
4) Pure Component
5) Controlled Component
6) Uncontrolled Complonent
==> component ke sath component bana sakte hai ===== yes
==> component ke ander component bana sakte hai ===== yes
when we no use ****export default****
------------------------------------------
export function Footer(){
return(
)
}
//other file
import {Footer} from './Assets/component/Footer';
---------------------------------------------
1) function components
---------------------------------------------
import '../assets/css/header.css'
function Header() {
return (
HEADER
);
}
export default Header;
---------------------------------------------
2) class components
---------------------------------------------
import {Component } from "react"
class Footer extends Component {
render(){
return (
);
}
}
export default Footer;
----------------------------------------------------------------------------------------------
JSX with React ===>
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=cxV9d6u0vfU
1) Javascript xml (jsx)
2) Write HTML and javascript together
3) Use Like HTML or XMLtags
function Header() {
return (
HEADER {5*10}
);
}
----------------------------------------------------------------------------------------------
Click Event and Function ===>
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=tmt7lf2nCBY
How to make click event
Call function in the button click
Variable in functional Component
--------------------------------------------------
On Click Function
--------------------------------------------------
function Apple1(){
alert("On Click funtion 1")
}
arrow function not run auto
----------------------------------------------------------------------------------------------
State in Functional Component ===> CONTENT-1
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=p7wZ_4sWZ4s
What is state
Use of state
Define state
Update state with a Button click
How state work
*** What is state ***
STATE ===> just like a object, we store data in STATE
*** Use of state ***
var variable not update in COMPONETN when we change
state update in COMPONETN when we change
jab hum state ko change/update karte hai to component ko pata chal jata hai kuch update ua hai VAR ke kesh me aisa kuch nahi hota
-------------------------------------------------------------
https://www.youtube.com/watch?v=GiyL4KFRNBA
ANIL SIDHU 1:35
https://www.youtube.com/watch?v=SS1I7m-G2kk&t=656s
THAPA TECHICAL
import { useState } from "react";
// use state NAME
const [data, setData] = useState("jitender")
function changeName() {
setData("RAJESH")
}
{data}
// use state number
const[number, setNumber] = useState(0);
function changeNumber(){
setNumber(number + 1)
}
{number}
-------------------------------------------------------------
******************************************** END STATE ********************************************
----------------------------------------------------------------------------------------------
Props with Functional Component ===> CONTENT-2
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=mpK8M4uJi-4
What are props
Use of props
Example with functional component
Update props on Button click
props ===> properties
when we data tranfer one component to another component we use props
props ===> just line parameter
1) Props in function component
2) Props in class component
3) Immutability of props
-------------------------------------------
1) Props in function component
-------------------------------------------
========== app.js page ========
========== component page ========
function Header(props) {
return (
HEADER {props.heanderName}
);
}
-------------------------------------------
2) Props in class component
-------------------------------------------
========== app.js page ========
========== component page ========
class Footer extends Component {
render(){
return (
-------------------------------------------
4 DESTRUCTURING PROPS
-------------------------------------------
1) Destructuring PROPS in function component
-------------------------------------------
function DesturcFuncProps(props) {
const {fname, lname} = props;
return (
DESTRUCTURING FUNC PROPS = {fname} {lname}
);
}
2) Destructuring PROPS in class component
-------------------------------------------
import {Component } from "react"
class DesturcClassProps extends Component {
render(){
const {fname, lname} = this.props;
return (
DESTRUCTURING CLASS PROPS = {fname} {lname}
);
}
}
----------------------------------------------------------------------------------------------
Get Input box value ===> CONTENT-3
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=1BHaLDRLQUo
Make Input field
Make function and get value
Make button and state
Get value on Button Click
************************************************
import { useState } from "react";
const[data, setData] = useState();
function getInputData(val){
setData(val.target.value);
}
input value: {data}
************************************************
----------------------------------------------------------------------------------------------
TERNARY OPERETOR ===> CONTENT-4
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=na0MVIomjmk
*************************************
---JAVASCRIPT---
that takes three operadnds
variable name = (condition) ? value1: value2
(age >= 18 ) ? if: else
var voteAge = 18;
//Conditional (ternary) Operator
document.getElementById("text16").innerHTML = (voteAge >= 18) ? "you can vote": "you can't vote" ;
*************************************
condition ? expression-True: expression-False
function Content4(){
const votAge = 18;
return(
)
}
----------------------------------------------------------------------------------------------
Hide and Show Element ===> CONTENT-5
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=fHJVWtBW6No
Make A div any other elemtnt
Make State for hiding and show element
Make button
Update state on button click
function Content5(){
const [data, setData] = useState(true);
return(
)
}
----------------------------------------------------------------------------------------------
Basic Form ===> CONTENT-6
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=4PFX52Qmqv8
https://www.youtube.com/watch?v=GiyL4KFRNBA 2.35 full video
Make HTML form
Add Some Field
Use state for field data
Submit and control form
// pagek ko refresh hone se rokne k liye
function getFormData(e){
e.preventDefault()
console.log(name, email, fclass, tmc)
}
// use state
const [name, setName] = useState("");
const [email, setEmail] = useState("");
const [fclass, setfclass] = useState("");
const [tmc, settmc] = useState(false);
----------------------------------------------------------------------------------------------
Conditional rendering | if Condition ===> CONTENT-7
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=3IWUZAeBzyc
Make Component
Use State
ternory operatore
Conditional rendering == if else condition
const [login, setLogin] = useState(true);
const [myuser, setMyuser] = useState(2);
{
login?
Welcome to jitender
:
Welcome to Guest
}
{
myuser==1?
Welcome to User-1
:
myuser==2?
Welcome to User-2
:
Welcome to User-3
}
----------------------------------------------------------------------------------------------
Pass function as Props ===> CONTENT-8
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=7BsYuB-5YXQ
*********************************************************************
APP.JS FILE
// contenet 8
function fun_content8(){
alert("pass function as props")
}
function fun_content8b(a,b){
return a*b;
}
*********************************************************************
COMPONENT FILE
function Content8(props) {
return (
)
}
----------------------------------------------------------------------------------------------
Life Cycle Methods in React ===> CONTENT-9
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=e2IUZyuNfgk
===PHASE 3===
1) Mounting
2) Updating
3) UnMounting
load poduct ==> Mounting
Update Product ==> Updating
Remove Product ==> UnMounting
***************************************
when Component is loaded
when Component is updated with state and props
when Component is removed.
--------------
1 Mounting
--------------
1 Constructor Life Cycle Methods 10
2 Render Life Cycle Methods 11
3 componentDidMount, life cycle method 12
when all html component load after DidMount call
--------------
2 Updating
--------------
componentDidUpdate life cycle method 13
shouldComponentUpdate 14
--------------
3 UnMounting
--------------
componentWillUnmount 15
----------------------------------------------------------------------------------------------
Constructor Life Cycle Methods in (class component) ===> CONTENT-10
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=RFEEqUrSecQ
What is constructor
Why this is important?
What we can do in this life cycle method?
class Content10 extends Component {
constructor(){
super();
this.state={
data:"jitender"
}
}
render() {
return (
Constructor Life Cycle Methods in (class component)
{this.state.data}
)
}
}
----------------------------------------------------------------------------------------------
Render Life Cycle Methods in (class component) ===> CONTENT-11
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=eSKDjVc7QQ4
Use of render Method.
Make Class Component
Use state and props with render.
render method. ==>
1 run/call when any html change, when component ready and load
2 run/call if any STATE and PROPS, are update render method run,
class Content11 extends Component {
// for state value
constructor(){
super();
this.state={
email:"jitender@gmail.com"
}
}
render() {
return (
)
}
}
----------------------------------------------------------------------------------------------
componentDidMount, life cycle method in (class component) ===> CONTENT-12
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=BCslNEYCRXc
Use of component DidMount Method.
Make Class Component.
No Effect of state and props
when COMPONENT full load then this method call ==> Component DidMount
HTML, DOM ready hone ke bad
API load karne k liye
component DidMount==> bar bar update nahi hota, state/props update hone per sirf render update hota hai
*******************************************************************
class Content12 extends Component {
// 1 constructor
constructor() {
super();
//console.log("constructor")
this.state={
name:"sumit sharma"
}
}
// 3 componentDidMount
componentDidMount() {
console.log("componentDidMount")
}
render() {
// 2 render
// console.log("render")
return (
when COMPONENT full load then this method call == Component DidMount
HTML, DOM ready hone ke bad
API load karne k liye
component DidMount == bar bar update nahi hota, state/props update hone per sirf render update hota hai
state value:- {this.state.name}
check consol.log
)
}
}
*******************************************************************
----------------------------------------------------------------------------------------------
componentDidUpdate life cycle method in (class component) ===> CONTENT-13
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=xPiph9AYYRw
Use of componentDidUpdate Method.
Make Class component.
Use with state and props
Previous Props and State
preProps, preState, snapshot 3 parameter in componentDidUpdate
componentDidUpdate == state ya props ke update hone k bad hi chalega, jitni bar state/props update hoga utni bar chalega
preProps, preState, snapshot 3 parameter in componentDidUpdate
*****************************************************
class Content13 extends Component {
// 1 constructor
constructor() {
super();
console.log("componentDidUpdate:--- constructor")
this.state={
name:"pankaj kumar",
count:0
}
}
// 3 componentDidUpdate
componentDidUpdate(preProps, preState, snapshot) {
console.log("componentDidUpdate:--- componentDidUpdate")
console.log("componentDidUpdate", preState.count, this.state.count)
}
render() {
//console.log("componentDidUpdate:--- render")
return (
componentDidUpdate == state ya props ke update hone k bad hi chalega, jitni bar state/props update hoga utni bar chalega
preProps, preState, snapshot 3 parameter in componentDidUpdate
state
state value:- {this.state.name}
check consol.log
state value number: {this.state.count}
)
}
}
*****************************************************
----------------------------------------------------------------------------------------------
shouldComponentUpdate life cycle method in (class component) ===> CONTENT-14
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=E878PZtIZLY
When shouldComponentUpdate called and Use.
It can stop rendering.
Use with state and props.
shouldComponentUpdate ==> ye apse poochta hai ki aapko component update karna hai k nahi
shouldComponentUpdate ==> ye rendering ko stop kar dena hai, iski default value false hoti hia
rendering ko chalu karne k liye true karna padta hai
*****************************************************
class Content14 extends Component {
constructor() {
super();
this.state = {
count: 0
}
}
//shouldComponentUpdate
shouldComponentUpdate() {
console.log("shouldComponentUpdate", this.state.count);
return true
// if (this.state.count > 5 && this.state.count < 10) {
// return true
// }
}
render() {
return (
shouldComponentUpdate == ye apse poochta hai ki aapko component update karna hai k nahi
shouldComponentUpdate == ye rendering ko stop kar deta hai, iski default value false hoti hia
rendering ko chalu karne k liye true karna padta hai
state
state value:- {this.state.count}
)
}
}
*****************************************************
----------------------------------------------------------------------------------------------
componentWillUnmount life cycle method in (class component) ===> CONTENT-15
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=kpqZ8o3kPk8&t=16s
when component will unmount called
example of component will unmount.
Use of component will unmount
jab bhi hamara component DOM se remove hoga componentWillUnmount call ho jayega
PARENT COMPONETNT
***************************************************
class Content15 extends Component {
constructor() {
super();
this.state = {
data: true
}
}
render() {
return (
componentWillUnmount == component ke remove hone ke bad call hota hai
parent componetn function componetn hosakta hai. lekin child component jisme componentWillUnmount call hota hai wo class component hi hona ch
)
}
}
***************************************************
----------------------------------------------------------------------------------------------
Hooks in React js ===> CONTENT-16
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=WoUpht1zcG0
https://www.youtube.com/watch?v=GiyL4KFRNBA
full 3.58
What are hooks in React js
How to use them
Example of React Hooks with useState
===Hooks===
With Hook, we can use class component features in functional components such as state, life cycle, pure component, etc
class component me == sate, life cycle, pure component, etc == ye sari chije hoti hai
function component me === ye sari chije nahi hoti == enhi feture ko use karne ke liye hum USE karte hai React Hooks ka
HOOKS defination:- kuch features hote hai class component me jo function component me nahi hoye unhi ko use karne ke liye hum HOOKS ka use karte hai like "useState"
===some Hooks name===
useCallback, useContext, useDebegValue, useEffect, useId, useImperativeHandle, useLayoutEffect, useMemo, useRenducer, useRef, useSyncExternalStore, useTransition, useState,
----------------------------------------------------------------------------------------------
useEffect hooks ===> CONTENT-17
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=zJeyz5mIXGQ
What is useEffect
How to use useEffect
Example useEffect
useEffect with State and props
-----------------------------
useEffect ==> ues hota hai as a life cycle method
stat/props update hone par call hoga,
isme condition bhi laga sakte hai kon si state/props update hone par call hoga
useEffect ==> Hooks as componentDidMount, componentDidUpdate, and componentWillUnmount combined
*********************************************************
function Content17() {
const[count, setCount] = useState(0);
// useEffect hooks
useEffect(()=>{
console.log("useEffect call")
})
return (
isme condition bhi laga sakte hai kon si state/props update hone par call hoga
useEffect == Hooks as componentDidMount, componentDidUpdate, and componentWillUnmount combined
update state
{count}
)
}
*********************************************************
----------------------------------------------------------------------------------------------
useEffect with Specific State and Props ===> CONTENT-18
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=80u8D2-Ro3s
What is useEffect
useEffect with Specific state
useEffect with Specific Props
STATE useEffect
****************************************************
function Content18() {
const[count, setCount] = useState(10);
const[data, setData] = useState(100);
// useEffect hooks state
useEffect(()=>{
console.log("useEffect state call")
},[data])
return (
)
}
****************************************************
----------------------------------------------------------------------------------------------
Style Type in React js ===> CONTENT-20
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=m8ZrNPykXes
How Many ways we have for style in React js
Use the normal stylesheet == like app.css, index.css
Style with the variable or Inline Style == inline css
CSS with Module == import style from '../css/custome.module.css';
Interview Question
**************************************************************
import style from '../css/custome.module.css';
function Content20() {
return (
How Many ways we have for style in React js == 3 type style
Use the normal stylesheet == like app.css, index.css
Style with the variable or Inline Style == inline css
CSS with Module == import style from '../css/custome.module.css';
normal stylesheet
style type 1
Inline Style
style type 2 use camel case in property
CSS with Module
style type 3 Module css custome.module.css
)
}
**************************************************************
----------------------------------------------------------------------------------------------
Install Bootstrap ===> CONTENT-21
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=3ER_2uoR52E
What is bootstrap
Ans:- bootsrap is a css and js library
Install Bootsrap
Ans:- Type - react bootstrap, and go to website click get started btn
1 npm install react-bootstrap bootstrap
2 import 'bootstrap/dist/css/bootstrap.min.css';
== this file use in index.js on top section
3 import { Button } from "react-bootstrap"; on top
****************************************************
import { Button } from "react-bootstrap";
function Content21() {
return (
)
}
****************************************************
----------------------------------------------------------------------------------------------
Handle Array with List ===> CONTENT-22
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=1MfE8LEYYZA
Make an array.
Why use map function, not for loop.
Make List with an array.
Make List with array of objects
list type of ARRAY
1. Normal Array 22
2. Object Array, List Array 22
3. Condition Array 23
4. Nested List Array 24
*************************************************************************************
function Content22() {
// array
const student1 = ["Rakesh", "Suresh", "Ramesh", "Anil"]
// array of objects
const student2 = [
{ name: "anil", email: "anil@test.com", phone: 1111111111 },
{ name: "suresh", email: "suresh@test.com", phone: 222222222 },
{ name: "kamal", email: "kamal@test.com", phone: 3333333333 }
]
return (
)
}
export default Content25_child;
*********************************************************
----------------------------------------------------------------------------------------------
React Fragment ===> CONTENT-26
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=ZlqnQvnj2j4
What is React Fragment? == multiple component/element ko handle/wrap karne ke liye
3 type --- div, <>>, Fragment tag
How to use it?
Use it with child component.
**************************************************
PARENT
import Content26_child from "./Content26_child";
import { Fragment } from "react";
import { Table } from "react-bootstrap";
function Content26() {
return (
>
)
}
**************************************************
----------------------------------------------------------------------------------------------
Send Data Child to Parent Component (Lifting State Up) ===> CONTENT-27
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=GStKM1PQkmI
Make a child component?
How pass props parent to a chld component?
Send data child to parent?
******************************************************************
PARENT
import Content27_child from "./Content27_child";
function Content27() {
// parent funciton to child
function parentAlert(deta1) {
alert(deta1);
}
function parentAlert2(deta2) {
alert(`name:- ${deta2.name}, email:- ${deta2.email}, phone:- ${deta2.phone} `);
}
return (
>
)
}
******************************************************************
----------------------------------------------------------------------------------------------
Pure Component STATE (in clsass component) CONTENT-28 ===> CONTENT-28
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=61z36tIx8sc
What is pure Component == ek feature hota hai jo hame react se import karna padta hai, ye sirf class component me hi chalta hai function componetnt ke liye useMemo hooks hota hai
How to use the Pure component? == pure component, component ki re-rendering hone se rokta hai, yadi same name bar bar print ho rahai ho to ye component ko re-render hone se rokta hai
pure Component agar value updatte ho rahi hai to re-rendering karega, agar value same hai to re-rendering nhi karega pure component
Pure Component example with State
Pure Component example with Props?
************************************************************************
import { Component, PureComponent } from "react";
class Content28 extends PureComponent {
constructor(){
super();
this.state={
count1:0,
count2:1
}
}
render() {
console.log("check STATE re-rendering-28")
return (
What is pure Component == ek feature hota hai jo hame react se import karna padta hai, ye sirf class component me hi chalta hai function componetnt ke liye useMemo hooks hota hai
How to use the Pure component? == pure component, component ki re-rendering hone se rokta hai, yadi same VALUE bar bar print ho rahai ho to ye component ko re-render hone se rokta hai
pure Component agar value updatte ho rahi hai to re-rendering karega, agar value same hai to re-rendering nhi karega pure component
Pure Component example with State
Pure Component example with Props?
Example with state
value update:- {this.state.count1}
value not update:- {this.state.count2}
)
}
}
************************************************************************
----------------------------------------------------------------------------------------------
Pure Component (PROPS) (in clsass component) CONTENT-29
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=61z36tIx8sc
**************************************************************************
PARENT
import { Component } from "react";
import Content29_child from "./Content29_child";
class Content29 extends Component {
constructor(){
super();
this.state={
count1:10,
count2:1
}
}
render() {
return (
>
)
}
}
**************************************************************************
----------------------------------------------------------------------------------------------
useMemo Hook in React js CONTENT-30
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=yM2q_joUmNQ
Why use useMemo Hook? == useMemo Hook, jab hum kisi component ke under kisi state ko update karne hai, usi componet ke ander koi function bhi hai to wo function bhi state ke update hone par call hota hai, usi ko rokne ke liye hum useMemo ka use karta hai. taki state update hone par sirf state update state call ho funciton bar bar call na ho
function ko bar bar update hone se rokta hai. usme condition laga sakte hai kis state ke update hone par call ho.
Understand Problem
Apply useMemo?
***********************************************************************
import { useMemo, useState } from "react";
function Content30() {
//USE STATE
const [count1, setCount1] = useState(1)
const [count2, setCount2] = useState(10)
// with normal funtion
// function multicount(){
// console.log("useMemo multicount function 30")
// return count1 * 5;
// }
const multiCountMemo = useMemo(function multicount(){
console.log("useMemo multicount function 30")
return count1 * 5;
},[count1])
return (
Why use useMemo Hook? == useMemo Hook, jab hum kisi component ke under kisi state ko update karne hai, usi componet ke ander koi function bhi hai to wo function bhi state ke update hone par call hota hai, usi ko rokne ke liye hum useMemo ka use karta hai. taki state update hone par sirf state update state call ho funciton bar bar call na ho
Understand Problem
Apply useMemo?
Example with State
state update value {count1}
state Unupdate value {count2}
useMemo hooks
Function value:- {multiCountMemo}
)
}
***********************************************************************
----------------------------------------------------------------------------------------------
Ref in React js (in class component) CONTENT-31
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=TL-j3kTam0E
ref == directly DOM ko manuplate karna hai, kisi ki property get kar li, color add kar diya, kisi element ka attrubute get kar liya
ref == react js bolta hai REF ko kam se kam use karna hai, REF ko power hi kisi ko hide show karne ki, color change karne ki, style ko change karne ki power hoti hai, ye DOM ko manuplate kar sakta hai. lekin react js bolta hai DOM ko manuplete nahi karna
Why use ref
Make Class Component
Ref use with example
************************************************************************
import { Component, createRef } from "react";
class Content31 extends Component {
constructor(){
super();
this.cus_input_ref= createRef();
}
// componentDidMount(){
// console.log(this.cus_input_ref.current.value="1000")
// }
getVal1(){
console.log(this.cus_input_ref.current.value)
this.cus_input_ref.current.style.color="#f00"
this.cus_input_ref.current.style.backgroundColor="#ccc"
}
render() {
return (
ref == directly DOM ko manuplate karna hai, kisi ki property get kar li, color add kar diya, kisi element ka attrubute get kar liya
ref == react js bolta hai REF ko kam se kam use karna hai, REF ko power hi kisi ko hide show karne ki, color change karne ki, style ko change karne ki power hoti hai, ye DOM ko manuplate kar sakta hai. lekin react js bolta hai DOM ko manuplete nahi karna
Why use ref
Make Class Component
Ref use with example
)
}
}
************************************************************************
----------------------------------------------------------------------------------------------
useRef Hook CONTENT-32
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=86EkZzXyScQ
useRef == directly DOM ko manuplate karna hai, kisi ki property get kar li, color add kar diya, kisi element ka attrubute get kar liya
useRef == react js bolta hai useRef ko kam se kam use karna hai, useRef ko power hi kisi ko hide show karne ki, color change karne ki, style ko change karne ki power hoti hai, ye DOM ko manuplate kar sakta hai. lekin react js bolta hai DOM ko manuplete nahi karna
Why use useRef
Ref use with example
Focus, color, value etc handle with useRef.
*********************************************************************************
import { useRef } from "react";
function Content32() {
// use useRef
let cust_input_ref = useRef(null);
// create funciton
function handleInput(){
alert("function call")
cust_input_ref.current.value="1000"
cust_input_ref.current.focus()
cust_input_ref.current.style.color="#f00"
cust_input_ref.current.style.backgroundColor="#ccc"
//cust_input_ref.current.style.display="none"
}
return (
useRef == directly DOM ko manuplate karna hai, kisi ki property get kar li, color add kar diya, kisi element ka attrubute get kar liya
useRef == react js bolta hai useRef ko kam se kam use karna hai, useRef ko power hi kisi ko hide show karne ki, color change karne ki, style ko change karne ki power hoti hai, ye DOM ko manuplate kar sakta hai. lekin react js bolta hai DOM ko manuplete nahi karna
Why use useRef
Ref use with example
Focus, color, value etc handle with useRef.
useRef Example
)
}
*********************************************************************************
----------------------------------------------------------------------------------------------
forwardRef CONTENT-33
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=xdywAqqHKio
Why use forwardRef. == input or button alag alag component me hai, parent component se child component me REF send karenge as a PROPS.
ek component se dusre component me REF send karne ke liye use hota hia FORWARDREF
Make Child Component
Pass Ref with props and use it
*******************************************************************************
PARENT
import { useRef } from "react";
import Content33_child from "./Content33_child";
function Content33() {
// ref
const input_ref = useRef(null);
//funciton
function updateInput() {
input_ref.current.value = "1000"
input_ref.current.style.color="#f00"
input_ref.current.style.backgroundColor="#ccc"
input_ref.current.focus()
}
return (
Why use forwardRef. == input or button alag alag component me hai, parent component se child component me REF send karenge as a PROPS.
ek component se dusre component me REF send karne ke liye use hota hia FORWARDREF
Make Child Component
Pass Ref with props and use it
)
}
*******************************************************************************
*******************************************************************************
CHILD
import { forwardRef } from "react";
function Content33_child(props, cus_ref) {
return (
<>
child 33
>
)
}
export default forwardRef(Content33_child);
*******************************************************************************
----------------------------------------------------------------------------------------------
Controlled Component CONTENT-34
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=5QkVq4gd8Mk
What is controlled component? == jiske under input field hoti hai,
agar input field ko state ke threw control karte hai to usko bolte hai. CONTROL COMPONENT
UNCONTROL COMPONETN == jo directly DOM ke threw control hote hai, jaise jquery/js ke therew ID ke threw
Make component.
Example of controlled component
********************************************************************************
import { useState } from "react";
function Content34() {
const [name, setName] = useState("jitender")
const [email, setEmail] = useState("jitender@gmail.com")
return (
)
}
export default Content34;
********************************************************************************
----------------------------------------------------------------------------------------------
Uncontrolled Component CONTENT-35
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=ajGbN7zpGQY
What is uncontrolled component? == jinme input field directly js/ref ke threw control hoti hai
condtion uncontrolled component == directly STATE ke threw control nahi ho rahi ho
use == useRef hook
*********************************************************************
import { useRef } from "react";
function Content35() {
let cus_input_ref1 = useRef();
let cus_input_ref2 = useRef();
//function
function submit_fun(e){
e.preventDefault()
console.log(`input 1:- ${cus_input_ref1.current.value}, input 2:- ${cus_input_ref2.current.value}, Content-35 `)
}
return (
What is uncontrolled component? == jinme input field directly js/ref ke threw control hoti hai
condtion uncontrolled component == directly STATE ke threw control nahi ho rahi ho
use == useRef hook
)
}
export default Content35;
*********************************************************************
----------------------------------------------------------------------------------------------
Simple HOC (Hight order component) CONTENT-36
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=VtSzJn41LgM
What is HOC(Hight order component)? == ek componetn jo dusre component ko as a PROPS leta ho
or alag se component return karta ho
jo ek component ko as a input le lor out output bhi as a value change karke de.
defination == a higher order component is function that takes component and return a new component.
Make 2 components
*********************************************************************
import { useState } from "react";
function Content36() {
return (
What is Routing == component ko pages me convert karna, or unme links lagana
Make 2 components
Install Route Package == Router, Route, link
install == search google === react router go to website == https://reactrouter.com/
npm install react-router-dom
Home
About
} />
} />
)
}
//home page
function HomePage() {
return (
Home page
This is home page webiset
)
}
//About us page
function AboutusPage() {
return (
Aboutus page
This is Aboutus page webiset
)
}
export default Content37;
*******************************************************************
----------------------------------------------------------------------------------------------
Rounting Example with Best Practices CONTENT-38
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=UjHH3sropDY
https://www.youtube.com/watch?v=dLvfJe-KlGI Create Browser url -- Thapa technical 1
https://www.youtube.com/watch?v=xaGNi81TlKo Create Navbar -- Thapa technical 2
Use React Router wrapper in index.js
Navbar file for Link
Components in Separate Files
Complete Example
****************************************************************
PARENTS MAIN PAGE
import Content38_header from './Content38_header';
import Content38_home from './Content38_home';
import Content38_about from './Content38_about';
import Content38_contact from './Content38_contact';
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
function Content38() {
return (
*/}
>
)
}
export default Content40_user1;
*******************************************************************
----------------------------------------------------------------------------------------------
API kya hoti hai CONTENT-41
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=fto0SavxDko
Application Programming Interface
API is a tool for Sharing data in applications.
Share data between platforms == like frontend and backend
Share data from pragramming language.
By Json
Because Json is supported by all programming language
----------------------------------------------------------------------------------------------
Call Get Method API CONTENT-42
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=K7u0aNj_kKQ
What is API?
Call API?
Get API data in State
Make List from API
Get Method == SHOW,
Post Method == STORE,
Put Method == UPDATE,
Delete Method == DELETE
fetch("url")
*************************************************************************
import { useEffect, useState } from 'react'
function Content42() {
//use state
const [data, setData] = useState([]);
useEffect(() => {
fetch("https://divineapi.heuristticminds.com/api/LocationList/Get-LocationList").then((result) => {
result.json().then((resp) => {
setData(resp)
//console.log(resp );
})
})
}, [])
//console.log(data );
return (
)
}
export default Content43;
***********************************************************************
----------------------------------------------------------------------------------------------
Postman CONTENT-44 =============
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=zuvgOh5TVIY
What is Postman === jab API me koi error aata hai, or pata nhi chalta kaha se error aaya hai, to us error ko solve karne k liye POSTMAN ka use kia jata hai, or test kia jata hai.
How to install it
How to use it
Test API
postman download == https://www.postman.com/downloads/
postman chrome plugin
https://chromewebstore.google.com/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=en
https://chromewebstore.google.com/detail/postman-interceptor/aicmkgpgakddgnaphhhpliifpcfhicfo
----------------------------------------------------------------------------------------------
POST Method with API CONTENT-45 ==============
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=3xhIcYeRgks
Why we use the POST Method? == API me Data Add karne ke liye.
Make A form.
Submit Data to API
Test Result
************************************************************************
************************************************************************
----------------------------------------------------------------------------------------------
Delete Method with API CONTENT-46 ==============
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=2i4HqvyTEag
Why we ues the Delete Method? == Delete karne ke liye ek Record ko
Add Delete Button in List
Make funciton and call delete API
************************************************************************
************************************************************************
----------------------------------------------------------------------------------------------
Pre-filled Form CONTENT-47
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=KHgWbPSctRE
Make a simple form.
Add Update Button in list
Set values in list
Populate values in form
****************************************************************
import { useEffect, useState } from "react";
function Content47() {
// for fatch api
const [data, setData] = useState([]);
// for pre filled form
const [name, setName] = useState();
const [add, setAdd] = useState();
const [phone, setPhone] = useState();
useEffect(() => {
fetch("https://divineapi.heuristticminds.com/api/LocationList/Get-LocationList").then((result) => {
result.json().then((resp) => {
setData(resp);
//console.log(resp);
setName(resp[0].locationOwner);
setAdd(resp[0].locationAddress);
setPhone(resp[0].locationContact);
})
})
}, [])
// pre filed updata btn funtion
function selectUser(id) {
console.log(data[id - 1])
setName(data[id - 1].locationOwner);
setAdd(data[id - 1].locationAddress);
setPhone(data[id - 1].locationContact);
}
return (
)
}
export default Content47;
****************************************************************
----------------------------------------------------------------------------------------------
Update Data with PUT Method CONTENT-48 ===================
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=ziFeFibUG3c
Recap Last Video
Update States for updated data
Send Data with PUT API
Test Result
----------------------------------------------------------------------------------------------
Previous State in Functional Component CONTENT-49
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=Nki0Nw_tRVU
What is Previous State
Why we need it
How to get it and use it
Another important and tricky example
*********************************************************************
import { useState } from "react";
function Content49() {
const [count, setCount] = useState(1)
const [count2, setCount2] = useState(10)
// function 1
function UpdateCounder() {
let rand = Math.floor(Math.random() * 10)
setCount((pre) => {
console.log(pre)
if (pre < 5) {
alert(`low value:- ${pre} `)
}
return rand
})
}
// function 2
function UpdateCounder2() {
setCount2((previous) => {
console.log(previous)
return count2 + 1;
})
}
return (
)
}
export default Content49;
*********************************************************************
----------------------------------------------------------------------------------------------
Previous Props with Hooks CONTENT-50
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=l8Frb4bz03U
What is Previous Props?
Why we need it
How to get it and use it
we will use useRef Hooks for it
********************************************************************
PARENT
import Content50_child from "./Content50_child"
import { useState } from "react";
function Content50() {
const [count, setCount] = useState(1)
return (
>
)
}
export default Content50_child;
********************************************************************
----------------------------------------------------------------------------------------------
State with Object CONTENT-51
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=ldsih80bAJw
Make a state with Object?
Try to update and understand the Problem?
Resoled it in 2 ways
********************************************************************
import { useState } from "react";
function Content51() {
const[data, setData] = useState({name: "jitender", age: 40});
return (
)
}
export default Content51;
********************************************************************
----------------------------------------------------------------------------------------------
React Context API with Hooks CONTENT-52 =================
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=gZFoGMn_3dw
What is Context API
Why do we need hook for Context API
Make Child Component
Child to parent data communication
MAKE parent component, MAKE child component, MAKE superChild component
Data Transfer, parent to child, parent to super child, child to parent
REDUX === Redux ek external library hai, wo hame alag se install karni padti hai
CONTEXT API = ye inbuild hoti hai react me
REDUX == use karne par sare component redux ke under aayega, PURA PROJECT under aayega
CONTEXT API == use karne par hame jitne component ki jarurat hai utne component dal sakte hai
example
----------------------------------------------------------------------------------------------
Basic Interview Question React Js (VIDEO-1) CONTENT-53
----------------------------------------------------------------------------------------------
1. https://www.youtube.com/watch?v=7gxqRdDt6nY
2. https://www.youtube.com/watch?v=WSZEQpl63DM
What is React js
React is a javascript library.
Use for Front end development with good speed
Developed by facebook
The current version is ---
WHAT IS COMPONENT
A piece of code that can resue like function
but more powerful than function
2 Types
Class and Funcitonal component
WHAT IS CLASS COMPONENT?
A Component that has ES 6 Class
More Complex and powerful than functional component
Because it has a lifecycle method and state.
No need to use Hooks
WHAT IS FUNCTINAL COMPONENT
A Component that has no ES 6 Class. It usesa simple JS function
Simple and need hooks for performing state and life cycle methods
Simple to define and recommened
WHAT IS STATE?
Information Holder inside component and it store any data like a variable
When we updte state component will rerender again but not in case of variable
We can not use state outside to component
WHAT IS PROPS?
Share data between component
We can send data parent to child, child to parent, and in sibling component
We can not change props in receiving component
WHAT IS LIFE CYCLE METHOD?
Some Method will execute on the component mount, update and unmount we call them life cycle method
EXAMPLE:
componentDidMount
componentDidUpdate
shouldComponentUpdate
componentWillUnmounting
WHAT ARE THE HOOKS
Functional component do not have state and life cycle metod
To use state and life cycle method we can import hooks in fucnctonal compoent
We can not use Hooks inside functinal component
WHAT ARE THE useState?
This is a hook for use state functional component
WHAT IS useEffect?
This is a hook for use lifecycle methods in a functional component
----------------------------------------------------------------------------------------------
Basic Interview Question React Js (VIDEO-2) CONTENT-54
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=WSZEQpl63DM
WHAT IS NPM
This is Node Package Manager which help us to install Library in React js
like map, form validation etc
WHAT IS PACKAGE.JSON?
This file profile application details such as version, node package, description etc
CAN WE USE REACT JS WITHOUT NPM?
Yes we can use it like jqury also. for that we can import in in root file qur use cdn
WHAT WE NEED TO DEVELP REACT APP?
For the Recommended way we need, npm node, and any code editor
Otherwise we can use CDN also
1 install node js
2 npm
3 code editor -- like vs code
CAN WE USE TS(type script) WITH REAT JS
Yes, we can
compiler install then we use == npm i compiler
https://www.youtube.com/watch?v=Xciunyug99U
CAN WE UES JQUERY, ANGULAR, AND BOOTSTRAP WITH REACT JS?
Yes we can
We can install pakages for jquery and bootstrap
We can use react package inside angular with npm install
npm i react-jquery
npm i react-bootstrap
CAN WE CONNECT REACT WITH THE DATABASE DIRCTLY?
No, We need API for DB data.
WHAT IS SPA?
It stands for Single Page Application
Which means Application look like single page and No reload or refresh on jumping on ther page and link.
We can make single page applicaton with react, angular and Vue
WHAT IS JEST?
Jest is a Unit Testing framework
Jest is Recommended and easy to use with react js
----------------------------------------------------------------------------------------------
Basic Form validation CONTENT-55
----------------------------------------------------------------------------------------------
https://www.youtube.com/watch?v=4PFX52Qmqv8&t=256s
Make Component
Make HTML Form
Define States
Apply Validation
*******************************************************************************
import { useState } from "react";
function Content55() {
let [user, setUser] =useState();
let [password, setPassword] =useState();
let [userErorr, setUserErorr] = useState(false);
let [passwordErorr, setPasswordErorr] = useState(false);
// form function
function loginForm(e){
if(user.length<3 || password.length<3){
alert("type current value")
}
else{
alert("form is submit")
}
e.preventDefault()
//alert("hello")
}
// User handler function
function userHandler(e){
let item = e.target.value
if(item.length<3){
setUserErorr(true);
}
else{
setUserErorr(false);
}
//console.log(e.target.value)
setUser(item)
}
// Password handler function
function passwordHandler(e){
let item = e.target.value
if(item.length<3){
setPasswordErorr(true);
}
else{
setPasswordErorr(false);
}
//console.log(e.target.value)
setPassword(item)
}
return (