SlideShare a Scribd company logo
1 of 32
Build web apps
with ReactJS
Hello!
I am Dhanushka
Software Engineer at Cambio Software Engineering
UCSC
Facebook Developer Circle - Colombo
2
Introduction
https://reactjs.org/
3
History
Jordan Walke, a software engineer at
Facebook
It was open-sourced at JSConf US in
May 2013
On Facebook's newsfeed in 2011
On Instagram since 2012
4
React Basics
A JavaScript library for building user
interfaces
16.5.2 is the latest version
5
React Basics
6
JSX − JSX is JavaScript syntax extension.
Components − React is all about components.
Unidirectional data flow − React implements
one-way data flow which makes it easy to
reason about your app.
React Basics
7
Covers only the view layer of the app
Complex React applications usually
require the use of additional libraries.
➔State management
➔Routing
➔Interaction with an API
Why React?
8
Uses virtual DOM which is a JavaScript object.
Can be used on client and server side as well as with
other frameworks.
Component and data patterns improve readability,
which helps to maintain larger apps.
Let’s get into React
9
Things needs to be installed
10
yarn or npm
a text editor
a web browser
Setting up the env
11
yarn init
Give main as src/index.js
yarn add react
yarn add react-dom
yarn add react-scriptsx
https://github.com/facebook/create-react-app
Setting up the environment
12
Folder Structure
public
--index.html
src
--index.js
package.json
Setting up the environment
13
index.html
<html lang="en">
<head>
<title>React App</title>
</head>
<body>
<div id="root"></div>
</body>
</html>
Create our first React component
14
import React from 'react'
import ReactDOM from 'react-dom'
Create our first React component
15
import React from 'react'
import ReactDOM from 'react-dom'
class HelloWorld extends React.Component {
render() {
return (
<div>
<div>Hello World!</div>
<div>Hello World!</div>
</div>
)
}
}
Create our first React component
16
import React from 'react'
import ReactDOM from 'react-dom'
class HelloWorld extends React.Component {
render() {
return (
<div>Hello World!</div>
)
}
}
ReactDOM.render(<HelloWorld />,
document.getElementById('root'));
Create our first React component
17
Next, Update package.json
"scripts": {
"start": "react-scripts start"
}
Create our first React component
18
yarn start
or
npm start
localhost:3000
Create our first React component
19
class HelloWorld extends React.Component {
render() {
return (
<div>Hello World!</div>
)
}
}
class HelloWorld extends React.Component {
render() {
return React.createElement("div", null, "Hello World");
}
Adding State to your Component
20
class WelcomeComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
name: 'John'
}
}
render() {
return (
<div>
Welcome {this.state.name}
</div>
)
}
}
Adding State to your Component
this.state inside of the constructor
will be part of that component’s state
component has the ability to modify
its own internal state. This can be
achieved by a method called
setState
21
Adding State to your Component
22
this.handleChange = this.handleChange.bind(this)
handleChange (e) {
this.setState({
name: e.target.value
})
}
Adding State to your Component
23
// Wrong
this.state.name = 'Hello';
Instead, use setState():
// Correct
this.setState({name: 'Hello'});
setState process
Last
Only update real
DOM with
necessary changes
First
Re-render virtual
DOM
Second
Run Diff algorithm
with previous virtual
DOM and new
virtual DOM
24
setState sends signal to notify our app some data has
changed,
Receiving State from Parent
Component
25
class Car extends React.Component {
render() {
return (
<div>This car is {this.props.color}.</div>
)
}
}
ReactDOM.render(<Car color="Red"/>,
document.getElementById('root'));
Receiving State from Parent
Component
26
yarn add prop-types
or
npm install prop-types
Receiving State from Parent
Component
27
Car.propTypes: {
color: PropTypes.string.isRequired
}
Car.defaultProps = {
color: 'Red'
}
Component LifeCycle
28
componentDidMount
Fired after the component mounted (after the initial render)
componentWillUnmount
Fired before the component will unmount
getDerivedStateFromProps
Fired when the component mounts and whenever the props change. Used
to update the state of a component when its props change
Let’s think in react!!
29
Simple ToDo App
Let’s build our ToDo App
30
npm
npm init react-app my-todo-app
Yarn
yarn create-react-app my-todo-app
create-react-app my-todo-app
npm i -g create-react-app
Let’s think in react!!
31
InputComponent
ShowListComponent
ItemComponent
Simple ToDo App
Thank you!
Any questions?
You can find me at:
Facebook @dhanushkach
dhanushka787@gmail.com
32

More Related Content

What's hot

Introduction to React
Introduction to ReactIntroduction to React
Introduction to ReactRob Quick
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation洪 鹏发
 
React js programming concept
React js programming conceptReact js programming concept
React js programming conceptTariqul islam
 
Getting Started with React.js
Getting Started with React.jsGetting Started with React.js
Getting Started with React.jsSmile Gupta
 
A Brief Introduction to React.js
A Brief Introduction to React.jsA Brief Introduction to React.js
A Brief Introduction to React.jsDoug Neiner
 
Spring Boot & Actuators
Spring Boot & ActuatorsSpring Boot & Actuators
Spring Boot & ActuatorsVMware Tanzu
 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JSArno Lordkronos
 
React for Dummies
React for DummiesReact for Dummies
React for DummiesMitch Chen
 
Getting started with Redux js
Getting started with Redux jsGetting started with Redux js
Getting started with Redux jsCitrix
 
Introduction to ReactJS
Introduction to ReactJSIntroduction to ReactJS
Introduction to ReactJSKnoldus Inc.
 
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...Edureka!
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Previewvaluebound
 
Angular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP ServicesAngular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP ServicesWebStackAcademy
 
React Router: React Meetup XXL
React Router: React Meetup XXLReact Router: React Meetup XXL
React Router: React Meetup XXLRob Gietema
 

What's hot (20)

Intro to React
Intro to ReactIntro to React
Intro to React
 
Introduction to React
Introduction to ReactIntroduction to React
Introduction to React
 
React and redux
React and reduxReact and redux
React and redux
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation
 
React js programming concept
React js programming conceptReact js programming concept
React js programming concept
 
Getting Started with React.js
Getting Started with React.jsGetting Started with React.js
Getting Started with React.js
 
React js
React jsReact js
React js
 
A Brief Introduction to React.js
A Brief Introduction to React.jsA Brief Introduction to React.js
A Brief Introduction to React.js
 
Spring Boot & Actuators
Spring Boot & ActuatorsSpring Boot & Actuators
Spring Boot & Actuators
 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JS
 
React for Dummies
React for DummiesReact for Dummies
React for Dummies
 
Introduction to Redux
Introduction to ReduxIntroduction to Redux
Introduction to Redux
 
Getting started with Redux js
Getting started with Redux jsGetting started with Redux js
Getting started with Redux js
 
reactJS
reactJSreactJS
reactJS
 
Introduction to ReactJS
Introduction to ReactJSIntroduction to ReactJS
Introduction to ReactJS
 
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...
 
React + Redux for Web Developers
React + Redux for Web DevelopersReact + Redux for Web Developers
React + Redux for Web Developers
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Preview
 
Angular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP ServicesAngular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP Services
 
React Router: React Meetup XXL
React Router: React Meetup XXLReact Router: React Meetup XXL
React Router: React Meetup XXL
 

Similar to Build web apps with react js

Fundamental concepts of react js
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react jsStephieJohn
 
Getting Started with React v16
Getting Started with React v16Getting Started with React v16
Getting Started with React v16Benny Neugebauer
 
React - Start learning today
React - Start learning today React - Start learning today
React - Start learning today Nitin Tyagi
 
React Hooks Best Practices in 2022.pptx
React Hooks Best Practices in 2022.pptxReact Hooks Best Practices in 2022.pptx
React Hooks Best Practices in 2022.pptxBOSC Tech Labs
 
Introduction to react_js
Introduction to react_jsIntroduction to react_js
Introduction to react_jsMicroPyramid .
 
React & Redux for noobs
React & Redux for noobsReact & Redux for noobs
React & Redux for noobs[T]echdencias
 
Introduction to React for Frontend Developers
Introduction to React for Frontend DevelopersIntroduction to React for Frontend Developers
Introduction to React for Frontend DevelopersSergio Nakamura
 
How to create components in react js
How to create components in react jsHow to create components in react js
How to create components in react jsBOSC Tech Labs
 
Introduction to react and redux
Introduction to react and reduxIntroduction to react and redux
Introduction to react and reduxCuong Ho
 
How To Integrate Native Android App With React Native.
How To Integrate Native Android App With React Native.How To Integrate Native Android App With React Native.
How To Integrate Native Android App With React Native.Techugo
 
React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥Remo Jansen
 

Similar to Build web apps with react js (20)

Fundamental concepts of react js
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react js
 
Intro react js
Intro react jsIntro react js
Intro react js
 
Learn react-js
Learn react-jsLearn react-js
Learn react-js
 
Getting Started with React v16
Getting Started with React v16Getting Started with React v16
Getting Started with React v16
 
React - Start learning today
React - Start learning today React - Start learning today
React - Start learning today
 
React Hooks Best Practices in 2022.pptx
React Hooks Best Practices in 2022.pptxReact Hooks Best Practices in 2022.pptx
React Hooks Best Practices in 2022.pptx
 
Introduction to react_js
Introduction to react_jsIntroduction to react_js
Introduction to react_js
 
React & Redux for noobs
React & Redux for noobsReact & Redux for noobs
React & Redux for noobs
 
Introduction to React for Frontend Developers
Introduction to React for Frontend DevelopersIntroduction to React for Frontend Developers
Introduction to React for Frontend Developers
 
How to create components in react js
How to create components in react jsHow to create components in react js
How to create components in react js
 
Simple React Todo List
Simple React Todo ListSimple React Todo List
Simple React Todo List
 
Introduction to react and redux
Introduction to react and reduxIntroduction to react and redux
Introduction to react and redux
 
How To Integrate Native Android App With React Native.
How To Integrate Native Android App With React Native.How To Integrate Native Android App With React Native.
How To Integrate Native Android App With React Native.
 
React outbox
React outboxReact outbox
React outbox
 
React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥
 
ReactJS.pptx
ReactJS.pptxReactJS.pptx
ReactJS.pptx
 
ReactJS
ReactJSReactJS
ReactJS
 
slides.pptx
slides.pptxslides.pptx
slides.pptx
 
slides.pptx
slides.pptxslides.pptx
slides.pptx
 
ReactJs
ReactJsReactJs
ReactJs
 

Recently uploaded

Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxnada99848
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 

Recently uploaded (20)

Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptx
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 

Build web apps with react js

  • 2. Hello! I am Dhanushka Software Engineer at Cambio Software Engineering UCSC Facebook Developer Circle - Colombo 2
  • 4. History Jordan Walke, a software engineer at Facebook It was open-sourced at JSConf US in May 2013 On Facebook's newsfeed in 2011 On Instagram since 2012 4
  • 5. React Basics A JavaScript library for building user interfaces 16.5.2 is the latest version 5
  • 6. React Basics 6 JSX − JSX is JavaScript syntax extension. Components − React is all about components. Unidirectional data flow − React implements one-way data flow which makes it easy to reason about your app.
  • 7. React Basics 7 Covers only the view layer of the app Complex React applications usually require the use of additional libraries. ➔State management ➔Routing ➔Interaction with an API
  • 8. Why React? 8 Uses virtual DOM which is a JavaScript object. Can be used on client and server side as well as with other frameworks. Component and data patterns improve readability, which helps to maintain larger apps.
  • 10. Things needs to be installed 10 yarn or npm a text editor a web browser
  • 11. Setting up the env 11 yarn init Give main as src/index.js yarn add react yarn add react-dom yarn add react-scriptsx https://github.com/facebook/create-react-app
  • 12. Setting up the environment 12 Folder Structure public --index.html src --index.js package.json
  • 13. Setting up the environment 13 index.html <html lang="en"> <head> <title>React App</title> </head> <body> <div id="root"></div> </body> </html>
  • 14. Create our first React component 14 import React from 'react' import ReactDOM from 'react-dom'
  • 15. Create our first React component 15 import React from 'react' import ReactDOM from 'react-dom' class HelloWorld extends React.Component { render() { return ( <div> <div>Hello World!</div> <div>Hello World!</div> </div> ) } }
  • 16. Create our first React component 16 import React from 'react' import ReactDOM from 'react-dom' class HelloWorld extends React.Component { render() { return ( <div>Hello World!</div> ) } } ReactDOM.render(<HelloWorld />, document.getElementById('root'));
  • 17. Create our first React component 17 Next, Update package.json "scripts": { "start": "react-scripts start" }
  • 18. Create our first React component 18 yarn start or npm start localhost:3000
  • 19. Create our first React component 19 class HelloWorld extends React.Component { render() { return ( <div>Hello World!</div> ) } } class HelloWorld extends React.Component { render() { return React.createElement("div", null, "Hello World"); }
  • 20. Adding State to your Component 20 class WelcomeComponent extends React.Component { constructor(props) { super(props); this.state = { name: 'John' } } render() { return ( <div> Welcome {this.state.name} </div> ) } }
  • 21. Adding State to your Component this.state inside of the constructor will be part of that component’s state component has the ability to modify its own internal state. This can be achieved by a method called setState 21
  • 22. Adding State to your Component 22 this.handleChange = this.handleChange.bind(this) handleChange (e) { this.setState({ name: e.target.value }) }
  • 23. Adding State to your Component 23 // Wrong this.state.name = 'Hello'; Instead, use setState(): // Correct this.setState({name: 'Hello'});
  • 24. setState process Last Only update real DOM with necessary changes First Re-render virtual DOM Second Run Diff algorithm with previous virtual DOM and new virtual DOM 24 setState sends signal to notify our app some data has changed,
  • 25. Receiving State from Parent Component 25 class Car extends React.Component { render() { return ( <div>This car is {this.props.color}.</div> ) } } ReactDOM.render(<Car color="Red"/>, document.getElementById('root'));
  • 26. Receiving State from Parent Component 26 yarn add prop-types or npm install prop-types
  • 27. Receiving State from Parent Component 27 Car.propTypes: { color: PropTypes.string.isRequired } Car.defaultProps = { color: 'Red' }
  • 28. Component LifeCycle 28 componentDidMount Fired after the component mounted (after the initial render) componentWillUnmount Fired before the component will unmount getDerivedStateFromProps Fired when the component mounts and whenever the props change. Used to update the state of a component when its props change
  • 29. Let’s think in react!! 29 Simple ToDo App
  • 30. Let’s build our ToDo App 30 npm npm init react-app my-todo-app Yarn yarn create-react-app my-todo-app create-react-app my-todo-app npm i -g create-react-app
  • 31. Let’s think in react!! 31 InputComponent ShowListComponent ItemComponent Simple ToDo App
  • 32. Thank you! Any questions? You can find me at: Facebook @dhanushkach dhanushka787@gmail.com 32

Editor's Notes

  1. It isn't necessary to use JSX in React development, but it is recommended. Allows us to write HTML like syntax which gets transformed to lightweight JavaScript objects. This will help you maintain the code when working on larger scale projects.
  2. This will improve apps performance, since JavaScript virtual DOM is faster than the regular DOM. A JavaScript representation of the actual DOM
  3. This will improve apps performance, since JavaScript virtual DOM is faster than the regular DOM. A JavaScript representation of the actual DOM
  4. This package serves as the entry point to the DOM and server renderers for React.