SlideShare a Scribd company logo
State, LifeCycle, Methods & Events
by Vinay
State
// Defining State
this.state = {
name: ‘Virat Kohli’
};
//This will not cause our component to update
this.state.name = ‘Mahendra Singh Dhoni’;
//Updating State
this.setState({
name: ‘Mahendra Singh Dhoni’
});
First Render
State Change
Props Change
Handling Events
Handling events with React elements is very similar to handling events on DOM elements. There are some syntactic differences:
● React events are named using camelCase, rather than lowercase.
● With JSX you pass a function as the event handler, rather than a string.
// In HTML
<button onclick="handleClick()">
Click Me
</button>
// In React
<button onClick={handleClick}>
Click Me
</button>
Methods
handleClick() {
// Do some stuff
}
// Calling Method
this.handleClick();
Methods with Events(Binding this in constructor)
handleClick() {
console.log(“Inside click event”, this);
}
// This binding is necessary to make `this` work in the callback. This binding is done inside
constructor.
this.handleClick = this.handleClick.bind(this);
// React Element
<button onClick={this.handleClick}>
Methods with Events(Using method as a property)
handleClick = () => {
console.log(“Inside click event”, this);
}
// React Element
<button onClick={this.handleClick}>
State, Life cycle, Methods & Events

More Related Content

Similar to State, Life cycle, Methods & Events (20)

PPTX
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
Karmanjay Verma
 
PPTX
Getting Started With ReactJS
Sandeep Kumar Patel
 
PPTX
React event
Ducat
 
PPTX
Introduction to React JS for beginners
Varun Raj
 
PPTX
react-slides.pptx
DayNightGaMiNg
 
PPTX
Dyanaimcs of business and economics unit 2
jpm071712
 
PDF
react-slides.pdf
DayNightGaMiNg
 
PDF
react-slides.pdf gives information about react library
janet736113
 
PDF
An introduction to React.js
Emanuele DelBono
 
PPTX
react-slidlkjfl;kj;dlkjopidfjhopijgpoerjpofjiwoepifjopweifjepoies.pptx
PrathamSharma77833
 
PPTX
TRAINING pptt efwoiefo weoifjoiewjfoifjow.pptx
PrathamSharma77833
 
PDF
Copy of React_JS_Notes.pdf
suryanarayana272799
 
PPTX
09f0a1aad0jhasvwdjhywy2qwgkyu09704b.pptx
BRIJESHKRSINGH
 
PPTX
edgegwfegfegwfe1aaddcbdhcdchdcdcbdvcdvbd009704b.pptx
smangla1957
 
PPTX
React - Start learning today
Nitin Tyagi
 
PPTX
Intro react js
Vijayakanth MP
 
PDF
React state management and side-effects – A Review of Hooks
IRJET Journal
 
PPTX
Introduction to React
Sebastian Pederiva
 
PDF
unit 3_Adv WTAdvanced Web Tecg Design_HTML_CSS_JAVASCRIPT_AJAX_PPT.pdf
GauravDwivedi695361
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
Karmanjay Verma
 
Getting Started With ReactJS
Sandeep Kumar Patel
 
React event
Ducat
 
Introduction to React JS for beginners
Varun Raj
 
react-slides.pptx
DayNightGaMiNg
 
Dyanaimcs of business and economics unit 2
jpm071712
 
react-slides.pdf
DayNightGaMiNg
 
react-slides.pdf gives information about react library
janet736113
 
An introduction to React.js
Emanuele DelBono
 
react-slidlkjfl;kj;dlkjopidfjhopijgpoerjpofjiwoepifjopweifjepoies.pptx
PrathamSharma77833
 
TRAINING pptt efwoiefo weoifjoiewjfoifjow.pptx
PrathamSharma77833
 
Copy of React_JS_Notes.pdf
suryanarayana272799
 
09f0a1aad0jhasvwdjhywy2qwgkyu09704b.pptx
BRIJESHKRSINGH
 
edgegwfegfegwfe1aaddcbdhcdchdcdcbdvcdvbd009704b.pptx
smangla1957
 
React - Start learning today
Nitin Tyagi
 
Intro react js
Vijayakanth MP
 
React state management and side-effects – A Review of Hooks
IRJET Journal
 
Introduction to React
Sebastian Pederiva
 
unit 3_Adv WTAdvanced Web Tecg Design_HTML_CSS_JAVASCRIPT_AJAX_PPT.pdf
GauravDwivedi695361
 

More from NodeXperts (20)

PDF
ECMA Script
NodeXperts
 
PDF
Apollo Server IV
NodeXperts
 
PDF
React Context API
NodeXperts
 
PDF
Devops - Microservice and Kubernetes
NodeXperts
 
PDF
Introduction to EC2 (AWS)
NodeXperts
 
PDF
Reactive Application Using METEOR
NodeXperts
 
PDF
Apollo server II
NodeXperts
 
PDF
Apollo Server
NodeXperts
 
PDF
Apollo Server III
NodeXperts
 
PPTX
Getting Reactive Data
NodeXperts
 
PPTX
Refs in react
NodeXperts
 
PPTX
Flow router, components and props
NodeXperts
 
PPTX
Using react with meteor
NodeXperts
 
PPTX
Introduction to Reactjs
NodeXperts
 
PPTX
Mobile apps using meteor - Part 1
NodeXperts
 
PPTX
Microservice architecture : Part 1
NodeXperts
 
PPTX
Reactive web applications using MeteorJS
NodeXperts
 
PPTX
Improving build solutions dependency management with webpack
NodeXperts
 
PPTX
Meteor workshop
NodeXperts
 
PPTX
Introduction to meteor
NodeXperts
 
ECMA Script
NodeXperts
 
Apollo Server IV
NodeXperts
 
React Context API
NodeXperts
 
Devops - Microservice and Kubernetes
NodeXperts
 
Introduction to EC2 (AWS)
NodeXperts
 
Reactive Application Using METEOR
NodeXperts
 
Apollo server II
NodeXperts
 
Apollo Server
NodeXperts
 
Apollo Server III
NodeXperts
 
Getting Reactive Data
NodeXperts
 
Refs in react
NodeXperts
 
Flow router, components and props
NodeXperts
 
Using react with meteor
NodeXperts
 
Introduction to Reactjs
NodeXperts
 
Mobile apps using meteor - Part 1
NodeXperts
 
Microservice architecture : Part 1
NodeXperts
 
Reactive web applications using MeteorJS
NodeXperts
 
Improving build solutions dependency management with webpack
NodeXperts
 
Meteor workshop
NodeXperts
 
Introduction to meteor
NodeXperts
 
Ad

Recently uploaded (20)

PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
Ad

State, Life cycle, Methods & Events

  • 1. State, LifeCycle, Methods & Events by Vinay
  • 2. State // Defining State this.state = { name: ‘Virat Kohli’ }; //This will not cause our component to update this.state.name = ‘Mahendra Singh Dhoni’; //Updating State this.setState({ name: ‘Mahendra Singh Dhoni’ });
  • 6. Handling Events Handling events with React elements is very similar to handling events on DOM elements. There are some syntactic differences: ● React events are named using camelCase, rather than lowercase. ● With JSX you pass a function as the event handler, rather than a string. // In HTML <button onclick="handleClick()"> Click Me </button> // In React <button onClick={handleClick}> Click Me </button>
  • 7. Methods handleClick() { // Do some stuff } // Calling Method this.handleClick();
  • 8. Methods with Events(Binding this in constructor) handleClick() { console.log(“Inside click event”, this); } // This binding is necessary to make `this` work in the callback. This binding is done inside constructor. this.handleClick = this.handleClick.bind(this); // React Element <button onClick={this.handleClick}>
  • 9. Methods with Events(Using method as a property) handleClick = () => { console.log(“Inside click event”, this); } // React Element <button onClick={this.handleClick}>