SlideShare a Scribd company logo
ReactJS
A quick introduction to Awesomeness
Copyright © Ronny Haase, 2017
Why should I care?
● Component based
● Declarative
● Fast - Client, Server, Universal
● Simple
● Free choice of ecosystem around (can also be considered a drawback)
Frontend engineering done right
Why should I care?
Because these guys do care a lot:
Airbnb, Atlassian, eBay, Dropbox, EyeEM, Facebook, Flipboard, Google, Khan
Academy, Mozilla, Netflix, PayPal, Pinterest, Rangle.io, Salesforce, Slack, Spotify, Tilt,
Twitch, Twitter, Uber, WalMart, Yahoo, Zalando
https://github.com/facebook/react/wiki/sites-using-react
The Pillars
<Component />s
Components
“Declarative
React makes it painless to create interactive UIs. Design simple views for each state in
your application, and React will efficiently update and render just the right
components when your data changes.
Declarative views make your code more predictable and easier to debug.”
“Component-Based
Build encapsulated components that manage their own state, then compose them to
make complex UIs.
Since component logic is written in JavaScript instead of templates, you can easily pass
rich data through your app and keep state out of the DOM.”
Components
Components
Two Types:
Presentational Container
Components are simply functions!
(internally “classes” are functions in JavaScript as well)
Presentational Components
Only markup, TodoItem
<div className=”TodoItem”>
<label className=”TodoItem-Title”>{props.title}</label>
<div className=”BtnGroup”>
<button className=”Btn” onClick={props.editItem}>Edit</button>
<button className=”Btn” onClick={props.removeItem}>Remove</button>
</div>
</div>
Presentational Components
<TodoItemWrapper>
<TodoItemTitle>{props.title}</TodoItemTitle>
<ButtonGroup>
<Button onClick={props.editItem}>Edit</Button>
<Button onClick={props.removeItem}>Remove</Button>
</ButtonGroup>
<TodoItemWrapper>
Presentational Components
const TodoItem = (props) =>
<TodoItemWrapper>
<TodoItemTitle>{props.title}</TodoItemTitle>
<ButtonGroup>
<Button onClick={props.editItem}>Edit</Button>
<Button onClick={props.removeItem}>Remove</Button>
</ButtonGroup>
</TodoItemWrapper>
Components
● Build as granular, encapsulated and generic components as possible
○ Better Performance
○ Easier Debugging
○ Easier Testing
○ More readable and declarative
○ Reusable
Container Components
● Components that have state (we learn about state later)
● Handles it’s state and passes it down as props to presentational components
// Component
const NameOutput = ({ enteredName }) => <h1>Hi! My name is {enteredName}</h1>
// Container
class EnterName extends Component {
render() {
return
<div>
<input onChange={(ev) => this.setState({ name: ev.target.value })} />
<NameOutput enteredName={this.state.name}
</div>
}
}
JSX
JavaScript XML
● No requirement
● Makes React declarative
● It’s XML (like HTML is) with full JavaScript power (you could do anything
within curly braces)
Elements
Elements are instances of Components
Lifecycle Methods
Hooks on certain state changes:
(Constructor), Mount, Unmount, Should Update?, Will Update, etc.
Explicit
Uni-Directional Data Flow
Data Types
The Two Data Types in React Applications
In React there are only two types of data:
● State
● Props
Props
● Read-only (!)
● Passed from the top
● Can be passed on down
○ Prefer specific or no passing down
○ Only pass on all props when necessary
● Are a reflection of your component tree
○ You only get relevant data
○ And only pass on the data relevant for your children
State
● If a component requires data that can change, or needs to store data you put them
into its State
● Immutable, plain Objects
● Pass on down as props
● Eventually Props can be the source (do not assign by reference!)
this.state = this.props.whatever
this.state = { ...this.props.whatever }
Data Flow
ReactJS - A quick introduction to Awesomeness
Looks familiar?
Yep, It’s a mess!
Your backend already did the MVC part, why repeat it on front-end?!
Just take the data and put them into your view!
Action = Click, request, new data
Dispatcher = Container Component, or e.g. Redux Dispatcher
Store = Container State, or e.g. Redux Store
View = Presentational Components
FLUX
React is the V in MVCReact is the V in MVC
VDOM
The Browser DOM is slow.
VDOM
● React keeps it’s own DOM (subtree) representation(s) and a copy of the actual
DOM in memory
● On Change (Props or State)
○ It diffs the DOMs in memory (fast!)
○ Parses tree and only rerenders elements where necessary in memory (faster!)
○ Mutates DOM all at once (even faster!)
Only one DOM mutation instead of multiple, each may requiring a browser repaint
○ Reconciliation
Does this concept sound familiar?
ReactJS - A quick introduction to Awesomeness
ReactJS - A quick introduction to Awesomeness
ReactJS - A quick introduction to Awesomeness
Bonuses
Flawless Server-Side & Universal Rendering
Even faster!
Client-side (SPA)
import { render } from ‘react-dom’;
const el = document.getElementById(‘mount’);
render(<MyComponent />, el);
Server-side
import { renderToString as render } from ‘react-dom/server’;
render(<MyComponent />);
Universal
import { renderToString as render } from ‘react-dom/server’;
return `
<div id=”mount”>
${render(<MyComponent />)}
</div>
`;
If you call the code from 2 slides before on client-side now, React will recognize the server-side rendered
component and only attach the missing parts powered by VDOM (very, very, very performant!)
Links
● Hacker Way: Rethinking Web App Development at Facebook
Official React announcement
● Learning Functional Programming with JavaScript by Anjana Vakil
Very basic but great introduction to Functional Programming
● Functional Programming Series by Eric Elliott
Great for diving deeper into Functional Programming
● How we built Twitter Lite
Great example for a light, mobile-first, progressive web app, built with React
Questions?
Let’s do some coding!
API
https://nodod-rsmmjhqasm.now.sh/todos
GET / - Get list of all tasks
POST / - Create task
GET /:id - Get specific task
PUT /:id - Update specific task
DELETE /:id - Delete specific task
Schema:
TodoItem { “title”: “Task title”, “completed”: false,
“created_at”: “1498566756549”, “updated_at”: “1498566794201” }
Run your own: https://github.com/ronnyhaase/nodod

More Related Content

PDF
Understanding Redux — Ilya Gelman
PDF
The Road To Redux
PPTX
Introduction to React JS for beginners
PPTX
Intro to React.js
PDF
PDF
An introduction to React.js
PPT
React js
PPTX
[Final] ReactJS presentation
Understanding Redux — Ilya Gelman
The Road To Redux
Introduction to React JS for beginners
Intro to React.js
An introduction to React.js
React js
[Final] ReactJS presentation

What's hot (20)

PPTX
Intro to React
PPTX
React & Redux JS
PPTX
Getting started with Redux js
PDF
Building React Applications with Redux
PPTX
Introduction to React JS
PDF
React and redux
PDF
How to Redux
PPTX
React JS - A quick introduction tutorial
PPTX
20180518 QNAP Seminar - Introduction to React Native
PPTX
The Benefits of Using React JS for Web Development!
PPTX
Academy PRO: React JS
PPTX
Introduction to React by Ebowe Blessing
PDF
Let's Redux!
PPTX
React + Redux + TypeScript === ♥
PDF
Understanding Facebook's React.js
PDF
React redux
PDF
Robust web apps with React.js
PDF
React&redux
PPTX
Redux workshop
ODP
Introduction to ReactJS
Intro to React
React & Redux JS
Getting started with Redux js
Building React Applications with Redux
Introduction to React JS
React and redux
How to Redux
React JS - A quick introduction tutorial
20180518 QNAP Seminar - Introduction to React Native
The Benefits of Using React JS for Web Development!
Academy PRO: React JS
Introduction to React by Ebowe Blessing
Let's Redux!
React + Redux + TypeScript === ♥
Understanding Facebook's React.js
React redux
Robust web apps with React.js
React&redux
Redux workshop
Introduction to ReactJS
Ad

Similar to ReactJS - A quick introduction to Awesomeness (20)

PPTX
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
PPTX
2.React tttttttttttttttttttttttttttttttt
PPTX
React workshop
PDF
Introduction to React for Frontend Developers
PPTX
reactJS
PPTX
PPTX
React Workshop: Core concepts of react
PPTX
ReactJS Code Impact
PDF
Workshop 19: ReactJS Introduction
PPTX
Introduction to React JS.pptx
PDF
ReactJS presentation
PPTX
Introduction to ReactJS UI Web Dev .pptx
PPTX
React js - The Core Concepts
PDF
Introduction Web Development using ReactJS
PPTX
ReactJS presentation.pptx
PPTX
React.js - The Dawn of Virtual DOM
PDF
Sviluppo di interfacce web con React.JS
PPTX
React + Flux = Joy
PDF
ReactJS for Programmers
PPTX
Dyanaimcs of business and economics unit 2
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
2.React tttttttttttttttttttttttttttttttt
React workshop
Introduction to React for Frontend Developers
reactJS
React Workshop: Core concepts of react
ReactJS Code Impact
Workshop 19: ReactJS Introduction
Introduction to React JS.pptx
ReactJS presentation
Introduction to ReactJS UI Web Dev .pptx
React js - The Core Concepts
Introduction Web Development using ReactJS
ReactJS presentation.pptx
React.js - The Dawn of Virtual DOM
Sviluppo di interfacce web con React.JS
React + Flux = Joy
ReactJS for Programmers
Dyanaimcs of business and economics unit 2
Ad

Recently uploaded (20)

PPTX
Cloud computing and distributed systems.
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
cuic standard and advanced reporting.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Electronic commerce courselecture one. Pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Spectroscopy.pptx food analysis technology
PDF
Review of recent advances in non-invasive hemoglobin estimation
Cloud computing and distributed systems.
Network Security Unit 5.pdf for BCA BBA.
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
Empathic Computing: Creating Shared Understanding
cuic standard and advanced reporting.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Programs and apps: productivity, graphics, security and other tools
Unlocking AI with Model Context Protocol (MCP)
20250228 LYD VKU AI Blended-Learning.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Electronic commerce courselecture one. Pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
A comparative analysis of optical character recognition models for extracting...
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Spectroscopy.pptx food analysis technology
Review of recent advances in non-invasive hemoglobin estimation

ReactJS - A quick introduction to Awesomeness

  • 1. ReactJS A quick introduction to Awesomeness Copyright © Ronny Haase, 2017
  • 2. Why should I care? ● Component based ● Declarative ● Fast - Client, Server, Universal ● Simple ● Free choice of ecosystem around (can also be considered a drawback) Frontend engineering done right
  • 3. Why should I care? Because these guys do care a lot: Airbnb, Atlassian, eBay, Dropbox, EyeEM, Facebook, Flipboard, Google, Khan Academy, Mozilla, Netflix, PayPal, Pinterest, Rangle.io, Salesforce, Slack, Spotify, Tilt, Twitch, Twitter, Uber, WalMart, Yahoo, Zalando https://github.com/facebook/react/wiki/sites-using-react
  • 6. Components “Declarative React makes it painless to create interactive UIs. Design simple views for each state in your application, and React will efficiently update and render just the right components when your data changes. Declarative views make your code more predictable and easier to debug.”
  • 7. “Component-Based Build encapsulated components that manage their own state, then compose them to make complex UIs. Since component logic is written in JavaScript instead of templates, you can easily pass rich data through your app and keep state out of the DOM.” Components
  • 8. Components Two Types: Presentational Container Components are simply functions! (internally “classes” are functions in JavaScript as well)
  • 9. Presentational Components Only markup, TodoItem <div className=”TodoItem”> <label className=”TodoItem-Title”>{props.title}</label> <div className=”BtnGroup”> <button className=”Btn” onClick={props.editItem}>Edit</button> <button className=”Btn” onClick={props.removeItem}>Remove</button> </div> </div>
  • 11. Presentational Components const TodoItem = (props) => <TodoItemWrapper> <TodoItemTitle>{props.title}</TodoItemTitle> <ButtonGroup> <Button onClick={props.editItem}>Edit</Button> <Button onClick={props.removeItem}>Remove</Button> </ButtonGroup> </TodoItemWrapper>
  • 12. Components ● Build as granular, encapsulated and generic components as possible ○ Better Performance ○ Easier Debugging ○ Easier Testing ○ More readable and declarative ○ Reusable
  • 13. Container Components ● Components that have state (we learn about state later) ● Handles it’s state and passes it down as props to presentational components // Component const NameOutput = ({ enteredName }) => <h1>Hi! My name is {enteredName}</h1> // Container class EnterName extends Component { render() { return <div> <input onChange={(ev) => this.setState({ name: ev.target.value })} /> <NameOutput enteredName={this.state.name} </div> } }
  • 14. JSX JavaScript XML ● No requirement ● Makes React declarative ● It’s XML (like HTML is) with full JavaScript power (you could do anything within curly braces)
  • 16. Lifecycle Methods Hooks on certain state changes: (Constructor), Mount, Unmount, Should Update?, Will Update, etc.
  • 19. The Two Data Types in React Applications In React there are only two types of data: ● State ● Props
  • 20. Props ● Read-only (!) ● Passed from the top ● Can be passed on down ○ Prefer specific or no passing down ○ Only pass on all props when necessary ● Are a reflection of your component tree ○ You only get relevant data ○ And only pass on the data relevant for your children
  • 21. State ● If a component requires data that can change, or needs to store data you put them into its State ● Immutable, plain Objects ● Pass on down as props ● Eventually Props can be the source (do not assign by reference!) this.state = this.props.whatever this.state = { ...this.props.whatever }
  • 24. Looks familiar? Yep, It’s a mess! Your backend already did the MVC part, why repeat it on front-end?! Just take the data and put them into your view!
  • 25. Action = Click, request, new data Dispatcher = Container Component, or e.g. Redux Dispatcher Store = Container State, or e.g. Redux Store View = Presentational Components
  • 26. FLUX
  • 27. React is the V in MVCReact is the V in MVC
  • 28. VDOM
  • 29. The Browser DOM is slow.
  • 30. VDOM ● React keeps it’s own DOM (subtree) representation(s) and a copy of the actual DOM in memory ● On Change (Props or State) ○ It diffs the DOMs in memory (fast!) ○ Parses tree and only rerenders elements where necessary in memory (faster!) ○ Mutates DOM all at once (even faster!) Only one DOM mutation instead of multiple, each may requiring a browser repaint ○ Reconciliation
  • 31. Does this concept sound familiar?
  • 36. Flawless Server-Side & Universal Rendering Even faster!
  • 37. Client-side (SPA) import { render } from ‘react-dom’; const el = document.getElementById(‘mount’); render(<MyComponent />, el);
  • 38. Server-side import { renderToString as render } from ‘react-dom/server’; render(<MyComponent />);
  • 39. Universal import { renderToString as render } from ‘react-dom/server’; return ` <div id=”mount”> ${render(<MyComponent />)} </div> `; If you call the code from 2 slides before on client-side now, React will recognize the server-side rendered component and only attach the missing parts powered by VDOM (very, very, very performant!)
  • 40. Links ● Hacker Way: Rethinking Web App Development at Facebook Official React announcement ● Learning Functional Programming with JavaScript by Anjana Vakil Very basic but great introduction to Functional Programming ● Functional Programming Series by Eric Elliott Great for diving deeper into Functional Programming ● How we built Twitter Lite Great example for a light, mobile-first, progressive web app, built with React
  • 42. Let’s do some coding!
  • 43. API https://nodod-rsmmjhqasm.now.sh/todos GET / - Get list of all tasks POST / - Create task GET /:id - Get specific task PUT /:id - Update specific task DELETE /:id - Delete specific task Schema: TodoItem { “title”: “Task title”, “completed”: false, “created_at”: “1498566756549”, “updated_at”: “1498566794201” } Run your own: https://github.com/ronnyhaase/nodod