SlideShare a Scribd company logo
The productive
developer guide to
React
Maurice de Beijer
@mauricedb
Who am I?
 Maurice de Beijer
 The Problem Solver
 MicrosoftAzure MVP
 Freelance developer/instructor
 Twitter: @mauricedb and @React_Tutorial
 Web: http://www.TheProblemSolver.nl
 E-mail: maurice.de.beijer@gmail.com
2© ABL - The Problem Solver
Topics
 What is React
 Pros and Cons
 Create ReactApp
 Building blocks
 Redux
 React-Router
 Best practices
© ABL - The Problem Solver 3
React is aJavaScript library
for building user interfaces
- Facebook -
© ABL - The Problem Solver 4
Companies
Using
React
 Facebook
 Instagram
 AirBNB
 Cloudflare
 Dropbox
 KhanAcademy
 Netflix
 Salesforce
 Twitter
 Uber
 Visa
 Wired
 Wordpress
 And many more…
© ABL - The Problem Solver 5
React
Tradeoffs
Advantages 
 Large community
 Small runtime library
 Fast
 Stable
 Simple and predictable API
 Server side rendering
 Open source (MIT license)
 Dedicated team at Facebook
Disadvantages 
 JavaScript focused
 Markup inside JavaScript
 Increases memory pressure
 Driven by Facebooks needs
 Not very opinionated
© ABL - The Problem Solver 6
Want opinionated?
© ABL - The Problem Solver 7
Components
 The basic building block of a React application
 Let you split the UI into independent pieces
 Think about each component in isolation
 A React application is a tree of components
 Components manage state
 And pass properties to child components as needed
© ABL - The Problem Solver 8
Component
tree
Application
Login Main Page
Header Billboard Genre List
Genre*
Movie*
Expanded
Movie
Playing
Movie
Simplified Netflix SPA
© ABL - The Problem Solver 9
JSX
 React is normally written using JSX syntax
 Combines ECMAScript and markup in one file
 Transpiled to regular ECMAScript for the browser
 Babel
 TypeScript
© ABL - The Problem Solver 10
Minimal
Example
import React, { Component } from "react";
import ReactDOM from "react-dom";
class App extends Component {
render() {
return (<div className="app">
<h2>ReactJS</h2>
<OtherComponent />
</div>);
}
}
ReactDOM.render(<App />,
document.getElementById("app"));
© ABL - The Problem Solver 11
Getting
Started
© ABL - The Problem Solver 12
Create
React
App
© ABL - The Problem Solver 13
Create
React
App
 Quickly start on a new React application
 Uses best practices, tools and libraries
 Babel
 Webpack
 Webpack development server
 Unit testing with Jest
 ESLint
 Service workers
 Add other packages like Redux or React-Router as needed
 Use the “eject” option to get full control
 At the cost of loosing very easy updates
© ABL - The Problem Solver 14
NWB
A great alternative to
Create ReactApp
© ABL - The Problem Solver 15
Props
 Props are “parameters” passed into a component
 Used to provide a component with data to work with
 Can be a function to call back into a parent component
 Props should never be modified
© ABL - The Problem Solver 16
State
 React uses a one way data flow
 State is data owned by a single component
 Can be passed to a child component as a prop
 Updating state in a component using setState() re-renders the
component
 This triggers child components to re-render
© ABL - The Problem Solver 17
Event handling
 Very similar to native event handling in HTML
 React binds event handlers using camelCase a naming convention
 React passes a synthetic event object
 The event object is reused between events!
 Use stopPropagation() and preventDefault() instead of return false
© ABL - The Problem Solver 18
An input form
class UserForm extends Component {
state = { firstName: "Maurice" };
onChange = e => this.setState({ [e.name]: e.value });
render() {
const { firstName } = this.state;
return (<form>
<InputWithLabel label="First name:"
value={firstName}
name="firstName"
onChange={this.onChange}
/>
</form>);
}
}
© ABL - The Problem Solver 19
An input
component
class InputWithLabel extends Component {
onChange = e => {
const { name, onChange } = this.props;
const { value } = e.target;
onChange({ name, value });
};
render() {
const { label, value } = this.props;
return (
<div>
<label>{label}</label>
<input type="text" value={value} onChange={this.onChange} />
</div>
);
}
}
© ABL - The Problem Solver 20
Redux
 Redux is a predictable state container for JavaScript apps
 Not just for React
 React bindings provided using the “react-redux” package
 Created by Dan Abramov
 Now a member of the React team at Facebook
 MobX is a great alternative to Redux
© ABL - The Problem Solver 21
A Redux app
import { Provider } from "react-redux";
const App = () => (
<div>
<h1>The Movies</h1>
<MoviesList />
</div>
);
ReactDOM.render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById("app")
);
© ABL - The Problem Solver 22
The Redux store
import {
combineReducers,
createStore
} from "redux";
const reducers = combineReducers({
movies
// Other reducers
});
const store = createStore(reducers);
© ABL - The Problem Solver 23
The reducer
const movies = function(state = [], action) {
switch (action.type) {
case "MOVIES-LOADED":
return action.movies;
default:
return state;
}
};
© ABL - The Problem Solver 24
The action
creator
const moviesLoaded = (movies) => {
return {
type: 'MOVIES-LOADED',
movies
}
};
© ABL - The Problem Solver 25
The component
class MovieList extends React.Component {
// ...
}
const mapStateToProps = (state) => ({
movies: state.movies
});
const mapDispatchToProps = (dispatch) => ({
moviesLoaded: movies =>
dispatch(moviesLoaded(movies))
});
export default connect(
mapStateToProps, mapDispatchToProps)(
MovieList);
© ABL - The Problem Solver 26
React-Router
 The most popular solution for routing in React
 Not from the team at Facebook
 A collection of navigational components
 Use the “react-router-dom” NPM package
© ABL - The Problem Solver 27
React-Router
import {
BrowserRouter, Switch, Route, Redirect
} from "react-router-dom";
class App extends Component {
render() {
return (<BrowserRouter>
<div className="container">
<h1>React-Router Example</h1>
<Switch>
<Route path="/movies" component={MovieList} />
<Route path="/movie/:id" component={MovieEdit} />
<Redirect to="/movies" />
</Switch>
</div>
</BrowserRouter>);
}
}
© ABL - The Problem Solver 28
Best practices
Components
 Keep components as small as possible
 Only use props and state in the render function
 Use pure functional components when possible
 Use Presentational and Container components
 Validate props in a component using prop-types
© ABL - The Problem Solver 29
Best practices
Performance
 Use immutable objects and PureComponent
 Don’t define fat arrow functions in the render
© ABL - The Problem Solver 30
Best practices
State
 Don’t store props or derived data in component state
 Only store data in state that is needed for rendering
 Use the functional version of setState()
 Don’t use Redux or MobX if you don’t need them
© ABL - The Problem Solver 31
Conclusion
 React is a great library for building user interfaces
 It’s fast and easy to use
 But not a perfect fit for every application
 Using Create React App is a great way to get started
 You can “eject” to get full control
 A React application is about Components
 With State and Props
 Redux and MobX are great tools for externalizing state
 Remember and use the best practices!
© ABL - The Problem Solver 32
Thank you
Maurice de Beijer - @mauricedb
© ABL - The Problem Solver 33

More Related Content

PDF
EMC Documentum - xCP 2.x Troubleshooting
PDF
Apollo. The client we deserve
PDF
React js t1 - introduction
PPT
]project-open[ Workflow Developer Tutorial Part 3
PDF
React js t8 - inlinecss
PDF
React js t7 - forms-events
PDF
Cloud Native Serverless Java — Orkhan Gasimov
EMC Documentum - xCP 2.x Troubleshooting
Apollo. The client we deserve
React js t1 - introduction
]project-open[ Workflow Developer Tutorial Part 3
React js t8 - inlinecss
React js t7 - forms-events
Cloud Native Serverless Java — Orkhan Gasimov

What's hot (20)

PPT
St Hilaire Ajax Start Odtug Nov 2009
PDF
React js t6 -lifecycle
PDF
React js t4 - components
PDF
Introducing enhancement framework.doc
PPTX
Rational Team Concert Build Component-Jazz Build Engine, Maven, Hudson/Jenkis
PDF
Overview of JSF 2.0
PDF
React js t5 - state
PDF
EMC Documentum xCP 2.x Tips for application migration v1.1
PPT
]project-open[ Workflow Developer Tutorial Part 2
PDF
Get rid of controllers in angular 1.5.x start using component directives
PPTX
React redux-redux-saga-rahil-memon
PDF
Evan Schultz - Angular Camp - ng2-redux
PPTX
Using Jenkins and Jmeter to build a scalable Load Testing solution
PDF
Lab5 RTC reports and Dashboards
PDF
API Testing following the Test Pyramid
PPTX
JahiaOne - Software Quality at Jahia
PDF
React js t3 - es6
PDF
React native app with type script tutorial
PDF
Redux and context api with react native app introduction, use cases, implemen...
PPTX
M365 global developer bootcamp 2019 PA
St Hilaire Ajax Start Odtug Nov 2009
React js t6 -lifecycle
React js t4 - components
Introducing enhancement framework.doc
Rational Team Concert Build Component-Jazz Build Engine, Maven, Hudson/Jenkis
Overview of JSF 2.0
React js t5 - state
EMC Documentum xCP 2.x Tips for application migration v1.1
]project-open[ Workflow Developer Tutorial Part 2
Get rid of controllers in angular 1.5.x start using component directives
React redux-redux-saga-rahil-memon
Evan Schultz - Angular Camp - ng2-redux
Using Jenkins and Jmeter to build a scalable Load Testing solution
Lab5 RTC reports and Dashboards
API Testing following the Test Pyramid
JahiaOne - Software Quality at Jahia
React js t3 - es6
React native app with type script tutorial
Redux and context api with react native app introduction, use cases, implemen...
M365 global developer bootcamp 2019 PA
Ad

Similar to The productive developer guide to React (20)

PPTX
How to implement multiple layouts using React router V4.pptx
PPTX
React - Start learning today
PPTX
Build web apps with react js
PPTX
React & Redux for noobs
PPTX
Better React state management with Redux
PPTX
Intro react js
PPTX
The new React
PPTX
React js programming concept
PPTX
React JS: A Secret Preview
PDF
Fundamental concepts of react js
PDF
Mastering React Server Components and Server Actions in React 19
PPTX
React Hooks Best Practices in 2022.pptx
PDF
React Native +Redux + ES6 (Updated)
PDF
Introduction to React for Frontend Developers
PPTX
PDF
Rest web service_with_spring_hateoas
PDF
React lecture
PDF
Introduction to react
PDF
React Lifecycle and Reconciliation
How to implement multiple layouts using React router V4.pptx
React - Start learning today
Build web apps with react js
React & Redux for noobs
Better React state management with Redux
Intro react js
The new React
React js programming concept
React JS: A Secret Preview
Fundamental concepts of react js
Mastering React Server Components and Server Actions in React 19
React Hooks Best Practices in 2022.pptx
React Native +Redux + ES6 (Updated)
Introduction to React for Frontend Developers
Rest web service_with_spring_hateoas
React lecture
Introduction to react
React Lifecycle and Reconciliation
Ad

More from Maurice De Beijer [MVP] (20)

PPTX
Full-stack App in half a Day: Next.js 15 Development Bootcamp
PPTX
Production-ready Next.js App with Cursor AI
PPTX
Building Robust Web Applications with Test-Driven Development and Playwright:...
PPTX
Practice TypeScript Techniques Building React Server Components App
PPTX
A foolproof Way to Estimate a Software Project
PPTX
Surati Tech Talks 2022 / Build reliable Svelte applications using Cypress
PPTX
Build reliable Svelte applications using Cypress
PPTX
Building Reliable Applications Using React, .NET & Azure
PPTX
Concurrent Rendering Adventures in React 18
PPTX
Building reliable applications with React, C#, and Azure
PPTX
Building large and scalable mission critical applications with React
PPTX
Building Reliable Applications Using React, .NET & Azure
PPTX
Why I am hooked on the future of React
PPTX
Building reliable web applications using Cypress
PPTX
Getting started with React Suspense and concurrent rendering
PPTX
React suspense, not just for Alfred Hitchcock
PPTX
From zero to hero with the Reactive extensions for JavaScript
PPTX
Why I am hooked on the future of React
PPTX
From zero to hero with the reactive extensions for JavaScript
PPTX
Why I am hooked on the future of React
Full-stack App in half a Day: Next.js 15 Development Bootcamp
Production-ready Next.js App with Cursor AI
Building Robust Web Applications with Test-Driven Development and Playwright:...
Practice TypeScript Techniques Building React Server Components App
A foolproof Way to Estimate a Software Project
Surati Tech Talks 2022 / Build reliable Svelte applications using Cypress
Build reliable Svelte applications using Cypress
Building Reliable Applications Using React, .NET & Azure
Concurrent Rendering Adventures in React 18
Building reliable applications with React, C#, and Azure
Building large and scalable mission critical applications with React
Building Reliable Applications Using React, .NET & Azure
Why I am hooked on the future of React
Building reliable web applications using Cypress
Getting started with React Suspense and concurrent rendering
React suspense, not just for Alfred Hitchcock
From zero to hero with the Reactive extensions for JavaScript
Why I am hooked on the future of React
From zero to hero with the reactive extensions for JavaScript
Why I am hooked on the future of React

Recently uploaded (20)

PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
August Patch Tuesday
PPTX
TLE Review Electricity (Electricity).pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
cloud_computing_Infrastucture_as_cloud_p
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
1. Introduction to Computer Programming.pptx
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PPTX
Spectroscopy.pptx food analysis technology
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Encapsulation theory and applications.pdf
A comparative study of natural language inference in Swahili using monolingua...
Per capita expenditure prediction using model stacking based on satellite ima...
Advanced methodologies resolving dimensionality complications for autism neur...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Group 1 Presentation -Planning and Decision Making .pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Encapsulation_ Review paper, used for researhc scholars
August Patch Tuesday
TLE Review Electricity (Electricity).pptx
Building Integrated photovoltaic BIPV_UPV.pdf
cloud_computing_Infrastucture_as_cloud_p
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Spectral efficient network and resource selection model in 5G networks
Programs and apps: productivity, graphics, security and other tools
1. Introduction to Computer Programming.pptx
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Spectroscopy.pptx food analysis technology
MIND Revenue Release Quarter 2 2025 Press Release
NewMind AI Weekly Chronicles - August'25-Week II
Encapsulation theory and applications.pdf

The productive developer guide to React

  • 1. The productive developer guide to React Maurice de Beijer @mauricedb
  • 2. Who am I?  Maurice de Beijer  The Problem Solver  MicrosoftAzure MVP  Freelance developer/instructor  Twitter: @mauricedb and @React_Tutorial  Web: http://www.TheProblemSolver.nl  E-mail: [email protected] 2© ABL - The Problem Solver
  • 3. Topics  What is React  Pros and Cons  Create ReactApp  Building blocks  Redux  React-Router  Best practices © ABL - The Problem Solver 3
  • 4. React is aJavaScript library for building user interfaces - Facebook - © ABL - The Problem Solver 4
  • 5. Companies Using React  Facebook  Instagram  AirBNB  Cloudflare  Dropbox  KhanAcademy  Netflix  Salesforce  Twitter  Uber  Visa  Wired  Wordpress  And many more… © ABL - The Problem Solver 5
  • 6. React Tradeoffs Advantages   Large community  Small runtime library  Fast  Stable  Simple and predictable API  Server side rendering  Open source (MIT license)  Dedicated team at Facebook Disadvantages   JavaScript focused  Markup inside JavaScript  Increases memory pressure  Driven by Facebooks needs  Not very opinionated © ABL - The Problem Solver 6
  • 7. Want opinionated? © ABL - The Problem Solver 7
  • 8. Components  The basic building block of a React application  Let you split the UI into independent pieces  Think about each component in isolation  A React application is a tree of components  Components manage state  And pass properties to child components as needed © ABL - The Problem Solver 8
  • 9. Component tree Application Login Main Page Header Billboard Genre List Genre* Movie* Expanded Movie Playing Movie Simplified Netflix SPA © ABL - The Problem Solver 9
  • 10. JSX  React is normally written using JSX syntax  Combines ECMAScript and markup in one file  Transpiled to regular ECMAScript for the browser  Babel  TypeScript © ABL - The Problem Solver 10
  • 11. Minimal Example import React, { Component } from "react"; import ReactDOM from "react-dom"; class App extends Component { render() { return (<div className="app"> <h2>ReactJS</h2> <OtherComponent /> </div>); } } ReactDOM.render(<App />, document.getElementById("app")); © ABL - The Problem Solver 11
  • 12. Getting Started © ABL - The Problem Solver 12
  • 13. Create React App © ABL - The Problem Solver 13
  • 14. Create React App  Quickly start on a new React application  Uses best practices, tools and libraries  Babel  Webpack  Webpack development server  Unit testing with Jest  ESLint  Service workers  Add other packages like Redux or React-Router as needed  Use the “eject” option to get full control  At the cost of loosing very easy updates © ABL - The Problem Solver 14
  • 15. NWB A great alternative to Create ReactApp © ABL - The Problem Solver 15
  • 16. Props  Props are “parameters” passed into a component  Used to provide a component with data to work with  Can be a function to call back into a parent component  Props should never be modified © ABL - The Problem Solver 16
  • 17. State  React uses a one way data flow  State is data owned by a single component  Can be passed to a child component as a prop  Updating state in a component using setState() re-renders the component  This triggers child components to re-render © ABL - The Problem Solver 17
  • 18. Event handling  Very similar to native event handling in HTML  React binds event handlers using camelCase a naming convention  React passes a synthetic event object  The event object is reused between events!  Use stopPropagation() and preventDefault() instead of return false © ABL - The Problem Solver 18
  • 19. An input form class UserForm extends Component { state = { firstName: "Maurice" }; onChange = e => this.setState({ [e.name]: e.value }); render() { const { firstName } = this.state; return (<form> <InputWithLabel label="First name:" value={firstName} name="firstName" onChange={this.onChange} /> </form>); } } © ABL - The Problem Solver 19
  • 20. An input component class InputWithLabel extends Component { onChange = e => { const { name, onChange } = this.props; const { value } = e.target; onChange({ name, value }); }; render() { const { label, value } = this.props; return ( <div> <label>{label}</label> <input type="text" value={value} onChange={this.onChange} /> </div> ); } } © ABL - The Problem Solver 20
  • 21. Redux  Redux is a predictable state container for JavaScript apps  Not just for React  React bindings provided using the “react-redux” package  Created by Dan Abramov  Now a member of the React team at Facebook  MobX is a great alternative to Redux © ABL - The Problem Solver 21
  • 22. A Redux app import { Provider } from "react-redux"; const App = () => ( <div> <h1>The Movies</h1> <MoviesList /> </div> ); ReactDOM.render( <Provider store={store}> <App /> </Provider>, document.getElementById("app") ); © ABL - The Problem Solver 22
  • 23. The Redux store import { combineReducers, createStore } from "redux"; const reducers = combineReducers({ movies // Other reducers }); const store = createStore(reducers); © ABL - The Problem Solver 23
  • 24. The reducer const movies = function(state = [], action) { switch (action.type) { case "MOVIES-LOADED": return action.movies; default: return state; } }; © ABL - The Problem Solver 24
  • 25. The action creator const moviesLoaded = (movies) => { return { type: 'MOVIES-LOADED', movies } }; © ABL - The Problem Solver 25
  • 26. The component class MovieList extends React.Component { // ... } const mapStateToProps = (state) => ({ movies: state.movies }); const mapDispatchToProps = (dispatch) => ({ moviesLoaded: movies => dispatch(moviesLoaded(movies)) }); export default connect( mapStateToProps, mapDispatchToProps)( MovieList); © ABL - The Problem Solver 26
  • 27. React-Router  The most popular solution for routing in React  Not from the team at Facebook  A collection of navigational components  Use the “react-router-dom” NPM package © ABL - The Problem Solver 27
  • 28. React-Router import { BrowserRouter, Switch, Route, Redirect } from "react-router-dom"; class App extends Component { render() { return (<BrowserRouter> <div className="container"> <h1>React-Router Example</h1> <Switch> <Route path="/movies" component={MovieList} /> <Route path="/movie/:id" component={MovieEdit} /> <Redirect to="/movies" /> </Switch> </div> </BrowserRouter>); } } © ABL - The Problem Solver 28
  • 29. Best practices Components  Keep components as small as possible  Only use props and state in the render function  Use pure functional components when possible  Use Presentational and Container components  Validate props in a component using prop-types © ABL - The Problem Solver 29
  • 30. Best practices Performance  Use immutable objects and PureComponent  Don’t define fat arrow functions in the render © ABL - The Problem Solver 30
  • 31. Best practices State  Don’t store props or derived data in component state  Only store data in state that is needed for rendering  Use the functional version of setState()  Don’t use Redux or MobX if you don’t need them © ABL - The Problem Solver 31
  • 32. Conclusion  React is a great library for building user interfaces  It’s fast and easy to use  But not a perfect fit for every application  Using Create React App is a great way to get started  You can “eject” to get full control  A React application is about Components  With State and Props  Redux and MobX are great tools for externalizing state  Remember and use the best practices! © ABL - The Problem Solver 32
  • 33. Thank you Maurice de Beijer - @mauricedb © ABL - The Problem Solver 33

Editor's Notes

  • #34: https://www.flickr.com/photos/stevendepolo/4582437563/