SlideShare a Scribd company logo
2
Most read
REACT
STATE
WELCOME TO DUCAT INDIA
Language | Industrial Training | Digital Marketing | Web Technology | Testing+ | Database |
Networking | Mobile Application | ERP | Graphic | Big Data | Cloud Computing
7070905090
info@ducatindia.com
REACT STATE
State is managed within the component in
which variables declared in function body.
State can be changed. State can be
accessed using “useState” Hook in
functional components and “this.state” in
class components. Hook is a new feature in
react. To use this expression it’s essential to
have good understanding of class
components. State hold information that used
for UI by browser.
To use state or state expressions in
react, let’s take an example of one
component-:
Output is shown with counter, as when
you click on 0 it will increment accordingly
as following-:
State is similar to props but state is fully controlled and it is more private by the
component. You can create state only in class component. It is possible to
update and modify the state.
There are two ways to initialize state in React Component.
1. Directly inside class
2. Inside the constructor
• When component class is created constructor is first method, it is right place to
add state.
• Class instance is already created in memory you can use ‘this’ to set properties
on it.
• When you write constructor make sure to call parent class constructor by super
props
• When you call super with props. React will make props available across the
component through this.props.
Like props state holds information about component. State is used when
component needs to keep track of information as when component itself can
create, update and use State. Understand with code example in which component
is created in which there is a button which keep tracks of how many times you
have clicked it.
Lets look at more factors about state-:
State is Changeable in which update Count is used again to explain
setState is run asynchronously and it needs callback function rather than
update state directly which saves the prevState after the updation too.
Now in last look step by step how counter flow works-:
1. First component is initialised and set.count is set to be 0
2. And the it renders within component with “click0times”
Clicked {this.state.count} times
3. And the it renders within component with
“click0times”Clicked {this.state.count} times
4. When user clicks the button then UpdateCount is
called.OnClick={ () => this.updateCount () }
5. With u”pdateCount” “setState” calls with callback to increase counter from
pervious state value.
6. And then setState call to render
7. In last component renders with clicked 1 times .
THANK YOU
REACT
STATE
7070905090
info@ducatindia.com

More Related Content

PPTX
State management in react applications (Statecharts)
PPTX
React workshop
PDF
Basics of React Hooks.pptx.pdf
PPTX
reactJS
PPTX
React JS - A quick introduction tutorial
PPTX
React + Redux Introduction
PPTX
Understanding react hooks
PPTX
React hooks
State management in react applications (Statecharts)
React workshop
Basics of React Hooks.pptx.pdf
reactJS
React JS - A quick introduction tutorial
React + Redux Introduction
Understanding react hooks
React hooks

What's hot (20)

PDF
Introduction to Redux
PPTX
React js
PPTX
React js programming concept
PPTX
Intro to React
PPTX
React render props
PDF
An Introduction to Redux
PPTX
What is component in reactjs
PPTX
PPTX
React JS: A Secret Preview
PPTX
Introduction to React
PPTX
ReactJS presentation.pptx
PDF
An introduction to React.js
PPTX
React Hooks
PDF
ReactJS presentation
PPTX
React js for beginners
PDF
React JS - Introduction
PPTX
Express js
PPTX
Introduction to React JS for beginners
PDF
State Management in Angular/React
Introduction to Redux
React js
React js programming concept
Intro to React
React render props
An Introduction to Redux
What is component in reactjs
React JS: A Secret Preview
Introduction to React
ReactJS presentation.pptx
An introduction to React.js
React Hooks
ReactJS presentation
React js for beginners
React JS - Introduction
Express js
Introduction to React JS for beginners
State Management in Angular/React
Ad

Similar to React state (20)

PPTX
How can you force react components to rerender without calling the set state ppt
PDF
Everything to Know About React Re-Rendering: A Comprehensive Guide
PDF
Workshop 19: ReactJS Introduction
PPTX
React State vs Props Introduction & Differences.pptx
PPTX
How to Detect a Click Outside a React Component.pptx
PPTX
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
PDF
Redux State Management System A Comprehensive Review
PPTX
FRONTEND BOOTCAMP 4.pptx
PDF
How to build a react native app with the help of react native hooks
PPTX
PPTX
React patterns
PPTX
React JS Interview Question & Answer
PDF
The battle between the states (all about flutter stateless & stateful widgets...
PPTX
Reactjs
PDF
Fundamental concepts of react js
ODP
Android App Development - 02 Activity and intent
PPTX
React Hooks Best Practices in 2022.pptx
DOC
Cis407 a ilab 6 web application development devry university
PDF
Jetpack Compose untuk UI Masa Depan Bagian 2 - Sidiq Permana
How can you force react components to rerender without calling the set state ppt
Everything to Know About React Re-Rendering: A Comprehensive Guide
Workshop 19: ReactJS Introduction
React State vs Props Introduction & Differences.pptx
How to Detect a Click Outside a React Component.pptx
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
Redux State Management System A Comprehensive Review
FRONTEND BOOTCAMP 4.pptx
How to build a react native app with the help of react native hooks
React patterns
React JS Interview Question & Answer
The battle between the states (all about flutter stateless & stateful widgets...
Reactjs
Fundamental concepts of react js
Android App Development - 02 Activity and intent
React Hooks Best Practices in 2022.pptx
Cis407 a ilab 6 web application development devry university
Jetpack Compose untuk UI Masa Depan Bagian 2 - Sidiq Permana
Ad

More from Ducat (20)

PPTX
Dot net training institute
PPTX
Mis certification
PDF
Devops certification
PDF
Best ethical hacking course online
PPTX
React js training course in noida
PPTX
Java for beginners
PPTX
Benfits of python
PPTX
Interactive reports development
PPTX
Abap report
PPTX
Sap abap database table
PPTX
Sap s4 hana saps next generation business suite
PPTX
Connect dashboard designer
PPTX
Major components of sap hana
PPTX
Schema in sap hana
PPTX
Sap hana attribute view
PPTX
Sap hana studio administration console
PPTX
What is ebs
PPTX
Introduction to mern
PPTX
Selenium tutorials
PPTX
Waits alerts and switch windows
Dot net training institute
Mis certification
Devops certification
Best ethical hacking course online
React js training course in noida
Java for beginners
Benfits of python
Interactive reports development
Abap report
Sap abap database table
Sap s4 hana saps next generation business suite
Connect dashboard designer
Major components of sap hana
Schema in sap hana
Sap hana attribute view
Sap hana studio administration console
What is ebs
Introduction to mern
Selenium tutorials
Waits alerts and switch windows

Recently uploaded (20)

PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
01-Introduction-to-Information-Management.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Complications of Minimal Access Surgery at WLH
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Cell Types and Its function , kingdom of life
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Basic Mud Logging Guide for educational purpose
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
Pre independence Education in Inndia.pdf
PDF
Classroom Observation Tools for Teachers
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
01-Introduction-to-Information-Management.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Complications of Minimal Access Surgery at WLH
human mycosis Human fungal infections are called human mycosis..pptx
Cell Types and Its function , kingdom of life
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Basic Mud Logging Guide for educational purpose
Abdominal Access Techniques with Prof. Dr. R K Mishra
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Microbial disease of the cardiovascular and lymphatic systems
O5-L3 Freight Transport Ops (International) V1.pdf
Week 4 Term 3 Study Techniques revisited.pptx
Pre independence Education in Inndia.pdf
Classroom Observation Tools for Teachers
STATICS OF THE RIGID BODIES Hibbelers.pdf

React state

  • 1. REACT STATE WELCOME TO DUCAT INDIA Language | Industrial Training | Digital Marketing | Web Technology | Testing+ | Database | Networking | Mobile Application | ERP | Graphic | Big Data | Cloud Computing 7070905090 info@ducatindia.com
  • 2. REACT STATE State is managed within the component in which variables declared in function body. State can be changed. State can be accessed using “useState” Hook in functional components and “this.state” in class components. Hook is a new feature in react. To use this expression it’s essential to have good understanding of class components. State hold information that used for UI by browser.
  • 3. To use state or state expressions in react, let’s take an example of one component-:
  • 4. Output is shown with counter, as when you click on 0 it will increment accordingly as following-:
  • 5. State is similar to props but state is fully controlled and it is more private by the component. You can create state only in class component. It is possible to update and modify the state. There are two ways to initialize state in React Component. 1. Directly inside class 2. Inside the constructor
  • 6. • When component class is created constructor is first method, it is right place to add state. • Class instance is already created in memory you can use ‘this’ to set properties on it. • When you write constructor make sure to call parent class constructor by super props • When you call super with props. React will make props available across the component through this.props.
  • 7. Like props state holds information about component. State is used when component needs to keep track of information as when component itself can create, update and use State. Understand with code example in which component is created in which there is a button which keep tracks of how many times you have clicked it.
  • 8. Lets look at more factors about state-: State is Changeable in which update Count is used again to explain setState is run asynchronously and it needs callback function rather than update state directly which saves the prevState after the updation too. Now in last look step by step how counter flow works-:
  • 9. 1. First component is initialised and set.count is set to be 0 2. And the it renders within component with “click0times” Clicked {this.state.count} times 3. And the it renders within component with “click0times”Clicked {this.state.count} times 4. When user clicks the button then UpdateCount is called.OnClick={ () => this.updateCount () } 5. With u”pdateCount” “setState” calls with callback to increase counter from pervious state value.
  • 10. 6. And then setState call to render 7. In last component renders with clicked 1 times .