SlideShare a Scribd company logo
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

PPTX
Introduction to React JS
PPTX
Intro to React
PPTX
Introduction to React JS for beginners
PPTX
Lab #2: Introduction to Javascript
PPTX
React render props
PPTX
PPT
Introduction to Javascript
PDF
React js
Introduction to React JS
Intro to React
Introduction to React JS for beginners
Lab #2: Introduction to Javascript
React render props
Introduction to Javascript
React js

What's hot (20)

PPTX
React JS - A quick introduction tutorial
PPTX
Introduction to React JS for beginners | Namespace IT
PPTX
React js for beginners
PDF
Spring Framework - Core
PDF
Spring Framework - MVC
PPTX
React + Redux Introduction
PPTX
Rethinking Best Practices
PPTX
React js programming concept
PPT
JavaScript & Dom Manipulation
PPTX
Javascript 101
PDF
React JS - Introduction
PPTX
Intro to React
PPTX
Reactjs
PPTX
ODP
Introduction to ReactJS
PDF
Introduction to React JS
PPTX
State management in react applications (Statecharts)
PDF
React JS and why it's awesome
PPTX
Introduction to Spring Boot
PDF
Angular Observables & RxJS Introduction
React JS - A quick introduction tutorial
Introduction to React JS for beginners | Namespace IT
React js for beginners
Spring Framework - Core
Spring Framework - MVC
React + Redux Introduction
Rethinking Best Practices
React js programming concept
JavaScript & Dom Manipulation
Javascript 101
React JS - Introduction
Intro to React
Reactjs
Introduction to ReactJS
Introduction to React JS
State management in react applications (Statecharts)
React JS and why it's awesome
Introduction to Spring Boot
Angular Observables & RxJS Introduction
Ad

Similar to Build web apps with react js (20)

PDF
React && React Native workshop
PPTX
Intro to React.js
PPTX
ReactJS (1)
PPTX
React_Introwvq2t2e2ewqtwtq31tef12duction.pptx
PDF
react.pdf
PPTX
Presentation on "An Introduction to ReactJS"
PPTX
React_Complete.pptx
PDF
0900 learning-react
PPTX
Dyanaimcs of business and economics unit 2
PPTX
PPTX
unit 2 React js.pptxdgdgdgdgdgdgdgdgdsgdgdg
PPTX
React - Start learning today
PDF
Tech Talk on ReactJS
PDF
Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...
PPTX
React + Flux = Joy
PPTX
Fullstack JS Workshop
PPT
PPTX
[Final] ReactJS presentation
PDF
Introduction to React for Frontend Developers
PDF
Learn react by Etietop Demas
React && React Native workshop
Intro to React.js
ReactJS (1)
React_Introwvq2t2e2ewqtwtq31tef12duction.pptx
react.pdf
Presentation on "An Introduction to ReactJS"
React_Complete.pptx
0900 learning-react
Dyanaimcs of business and economics unit 2
unit 2 React js.pptxdgdgdgdgdgdgdgdgdsgdgdg
React - Start learning today
Tech Talk on ReactJS
Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...
React + Flux = Joy
Fullstack JS Workshop
[Final] ReactJS presentation
Introduction to React for Frontend Developers
Learn react by Etietop Demas
Ad

Recently uploaded (20)

PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Digital Strategies for Manufacturing Companies
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Nekopoi APK 2025 free lastest update
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
medical staffing services at VALiNTRY
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
history of c programming in notes for students .pptx
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
Online Work Permit System for Fast Permit Processing
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Digital Strategies for Manufacturing Companies
How Creative Agencies Leverage Project Management Software.pdf
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Nekopoi APK 2025 free lastest update
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
medical staffing services at VALiNTRY
Wondershare Filmora 15 Crack With Activation Key [2025
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
history of c programming in notes for students .pptx
2025 Textile ERP Trends: SAP, Odoo & Oracle
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Online Work Permit System for Fast Permit Processing
Which alternative to Crystal Reports is best for small or large businesses.pdf
PTS Company Brochure 2025 (1).pdf.......
Odoo Companies in India – Driving Business Transformation.pdf
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...

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

  • #7: 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.
  • #9: This will improve apps performance, since JavaScript virtual DOM is faster than the regular DOM. A JavaScript representation of the actual DOM
  • #11: This will improve apps performance, since JavaScript virtual DOM is faster than the regular DOM. A JavaScript representation of the actual DOM
  • #12: This package serves as the entry point to the DOM and server renderers for React.