SlideShare a Scribd company logo
The new React
Maurice de Beijer - @mauricedb
 Maurice de Beijer
 The Problem Solver
 Microsoft MVP
 Freelance developer/instructor
 Twitter: @mauricedb
 Web: http://www.TheProblemSolver.nl
 E-mail: maurice.de.beijer@gmail.com
2ABL - The Problem Solver
The React
Newsletter
© ABL - The Problem Solver 3
http://bit.ly/ReactNewsletter
Topics
 Intro into React hooks
 Basic hooks
 useState()
 useEffect()
 useEffect() with asynchronous actions
 useContext()
 Custom hooks
 Advanced hooks
 useDebugValue()
 useMemo()
 useReducer()
 useRef()
 Suspense
 lazy()
 StrictMode
 ConcurrentMode
 React Cache
© ABL - The Problem Solver 4
Follow along
 Git repository with slides and code
 https://github.com/mauricedb/the-new-react-vilnius-2019
© ABL - The Problem Solver 5
Type it out
by hand?
“Typing it drills it into your brain much better than
simply copying and pasting it.You're forming new
neuron pathways.Those pathways are going to
help you in the future. Help them out now!”
© ABL - The Problem Solver 6
Prerequisites
Install Node & NPM
© ABL - The Problem Solver 7
Install
Node.js & NPM
© ABL - The Problem Solver 8
Basic hooks
© ABL - The Problem Solver 9
useState()
 Returns a persisted stateful value and a function to update it
 Values can be object or scalar values
 Starts with an initial value
 Can be a lazy initialization function
 The updater function replaces the original state
 Doesn’t merge state like the class based setState()
 The update value can also be a function
© ABL - The Problem Solver 10
Class based
© ABL - The Problem Solver 11
With Hooks
© ABL - The Problem Solver 12
useEffect()
 Accepts a function that contains imperative code
 The code is used to execute (asynchronous) side effects
 useEffect() fires after layout and paint, during a deferred event
 Use useLayoutEffect() for code that should not be deferred
 Runs both on component mount as well as updates
 Control when using the dependencies array
 Optionally return a cleanup function
© ABL - The Problem Solver 13
Class based
© ABL - The Problem Solver 14
With Hooks
© ABL - The Problem Solver 15
useEffect()
with
asynchronous
actions
 useEffect() is great for async actions like AJAX requests
 👉 Make sure to never return a promise 👈
 Use the effect cleanup function to cancel a pending request
© ABL - The Problem Solver 16
Class based
© ABL - The Problem Solver 17
With Hooks
© ABL - The Problem Solver 18
useContext()
 Accepts a context object and returns the current context value
 Much easier then render props 😺
 Needs to be part of <Context.Provider/> component subtree
© ABL - The Problem Solver 19
Render props
© ABL - The Problem Solver 20
With Hooks
© ABL - The Problem Solver 21
Custom hooks
 Extract code from a component into a reusable custom hook
 Makes the code more reusable
 Can use other hooks as needed
 Just like a functional component
 Must be named useSomething()
 For React to recognize it as a hook
 Publish to NPM for others to use if you like
 See: https://nikgraf.github.io/react-hooks/
© ABL - The Problem Solver 22
Before
© ABL - The Problem Solver 23
The
component
with custom
hook
© ABL - The Problem Solver 24
The custom
hook
© ABL - The Problem Solver 25
useDebugValue()  Displays a label for a custom hook in React DevTools
 👉 Useful for custom Hooks that are part of shared libraries 👈
© ABL - The Problem Solver 26
With Hooks
© ABL - The Problem Solver 27
Additional Hooks
© ABL - The Problem Solver 28
useMemo()
 Returns a memoized value
 Same inputs return the same result
 It’s a performance optimization
 Not as a guarantee
© ABL - The Problem Solver 29
Before
© ABL - The Problem Solver 30
With
useMemo()
© ABL - The Problem Solver 31
useReducer()
 A more powerful version of useState()
 Uses a reducer function to manage state
 Just like Redux
 The reducer function always has the same signature
 (oldState, action) => newState
 Preferred when state logic is more complex
 Much easier to write in aTDD style
 👉The dispatch function won’t change with re-renders 👈
© ABL - The Problem Solver 32
With useState()
© ABL - The Problem Solver 33
Manage state
© ABL - The Problem Solver 34
Update
selection
© ABL - The Problem Solver 35
Update state
© ABL - The Problem Solver 36
With useReducer()
© ABL - The Problem Solver 37
useReducer()
© ABL - The Problem Solver 38
The reducer
function
© ABL - The Problem Solver 39
Dispatch
selection
© ABL - The Problem Solver 40
Dispatch state
changes
© ABL - The Problem Solver 41
useRef()
 Maintain state between each re-render
 Without triggering a render on updates
 Typically used for DOM object and useEffect()
 But can be used for any kind of state
© ABL - The Problem Solver 42
Manipulating DOM
objects with useRef()
© ABL - The Problem Solver 43
Using a DOM
object
© ABL - The Problem Solver 44
Remembering other
values using useRef()
© ABL - The Problem Solver 45
Wrong
solution
© ABL - The Problem Solver 46
With useRef()
© ABL - The Problem Solver 47
Concurrent React
© ABL - The Problem Solver 48
lazy()
 Create a component that is loaded dynamically
 With automatic bundle splitting by Webpack
 Requires a <Suspense /> component as a parent
 The fallback UI is required
 Typically a spinner or something similar
© ABL - The Problem Solver 49
Eager Loading
© ABL - The Problem Solver 50
Lazy Loading
© ABL - The Problem Solver 51
StrictMode
 The <StrictMode /> component helps prepare for async rendering
 Warns about unsafe lifecycle functions like componentWillMount()
 As well as other deprecated React features
 Will try to detect illegal side effects by rendering twice
 The same applies to some state management functions
 👉 Does nothing in a production build 👈
 Will make a development build run slower
© ABL - The Problem Solver 52
Not strict
© ABL - The Problem Solver 53
Using
<StrictMode/>
© ABL - The Problem Solver 54
Fixing the strict error
© ABL - The Problem Solver 55
Before
© ABL - The Problem Solver 56
No more
<ListGroup/>
© ABL - The Problem Solver 57
Concurrent
mode
 React can render in concurrent mode
 Rendering happens in time slices
 React can prioritize user events over other work
 Results in more responsive applications
 Either for the whole application using ReactDOM.createRoot()
 Or a component subtree using <ConcurrentMode/>
© ABL - The Problem Solver 58
Time
Slicing
Demo
© ABL - The Problem Solver 59
Current
rendering
© ABL - The Problem Solver 60
Concurrent
rendering
© ABL - The Problem Solver 61
ReactCache
 Creates a resource manager to load data asynchronous
 Can work with anything that return a promise
 Can be called from a components render() function
 Will pause rendering until the promise resolves
 💔The NPM package is broken for the current React version 💔
© ABL - The Problem Solver 62
Rendering
asynchronous
data
© ABL - The Problem Solver 63
The
asynchronous
resource
© ABL - The Problem Solver 64
Conclusion
 The future of React is bright
 Functional components and hooks is the future of components
 But class based components will continue to work
 Concurrent React makes large complex application responsive
 Easy to implement in most cases
 React Cache will make data loading easier
 But not quite yet
© ABL - The Problem Solver 65
Maurice de Beijer
@mauricedb
© ABL - The Problem Solver 66

More Related Content

PPTX
React and Flux life cycle with JSX, React Router and Jest Unit Testing
PPTX
Concurrent Rendering Adventures in React 18
ODP
Parallel builds in Eclipse IDE workspace
PDF
TestWorks Conf Performance testing made easy with gatling - Guillaume Corré
ODP
Adopting Debug Adapter Protocol in Eclipse IDE: netcoredbg (.NET debugger) ca...
ODP
Parallel builds in Eclipse IDE workspace - EclispeCon Europe 2018
PPTX
Qt test framework
 
PPTX
React-JS Component Life-cycle Methods
React and Flux life cycle with JSX, React Router and Jest Unit Testing
Concurrent Rendering Adventures in React 18
Parallel builds in Eclipse IDE workspace
TestWorks Conf Performance testing made easy with gatling - Guillaume Corré
Adopting Debug Adapter Protocol in Eclipse IDE: netcoredbg (.NET debugger) ca...
Parallel builds in Eclipse IDE workspace - EclispeCon Europe 2018
Qt test framework
 
React-JS Component Life-cycle Methods

What's hot (20)

ODP
Gatling
PPTX
Example of TAF with batch execution of test cases
ODP
Jenkins Pipelining and Gatling Integration
PPTX
Scaling React and Redux at IOOF
PDF
Workshop 22: React-Redux Middleware
ODP
Gatling - Stress test tool
PDF
Angular 2 observables
PDF
Corso su ReactJS
PDF
Three Lessons about Gatling and Microservices
PPTX
Single Page Applications with AngularJS 2.0
PPTX
ReactJs
PPTX
Gatling Tool in Action at Devoxx 2012
PDF
Idiomatic Gradle Plugin Writing - GradleSummit 2016
PDF
React state management with Redux and MobX
PDF
Mobx for Dummies - Yauheni Nikanowich - React Warsaw #5
PPTX
Academy PRO: React JS
PPTX
React js Rahil Memon
PDF
React js use contexts and useContext hook
PPTX
Angular JS in 2017
PDF
Gatling - Bordeaux JUG
Gatling
Example of TAF with batch execution of test cases
Jenkins Pipelining and Gatling Integration
Scaling React and Redux at IOOF
Workshop 22: React-Redux Middleware
Gatling - Stress test tool
Angular 2 observables
Corso su ReactJS
Three Lessons about Gatling and Microservices
Single Page Applications with AngularJS 2.0
ReactJs
Gatling Tool in Action at Devoxx 2012
Idiomatic Gradle Plugin Writing - GradleSummit 2016
React state management with Redux and MobX
Mobx for Dummies - Yauheni Nikanowich - React Warsaw #5
Academy PRO: React JS
React js Rahil Memon
React js use contexts and useContext hook
Angular JS in 2017
Gatling - Bordeaux JUG
Ad

Similar to The new React (20)

PPTX
Better React state management with Redux
PPTX
Why I am hooked on the future of React
PPTX
Why I am hooked on the future of React
PPTX
The productive developer guide to React
PPTX
I am hooked on React
PDF
Mastering React Server Components and Server Actions in React 19
PPTX
Building large and scalable mission critical applications with React
PPTX
Building Reliable Applications Using React, .NET & Azure
PPTX
Session 03_04-Working with React Native.pptx
PPTX
React suspense, not just for Alfred Hitchcock
PDF
React Lifecycle and Reconciliation
PPTX
Building high performance web applications
PPTX
Web Performance & Latest in React
PPTX
Building high performance web applications
PPTX
Building high performance web applications
PPTX
Building reliable applications with React, C#, and Azure
PPTX
React gsg presentation with ryan jung &amp; elias malik
PDF
0900 learning-react
PPTX
Production-ready Next.js App with Cursor AI
PDF
react.pdf
Better React state management with Redux
Why I am hooked on the future of React
Why I am hooked on the future of React
The productive developer guide to React
I am hooked on React
Mastering React Server Components and Server Actions in React 19
Building large and scalable mission critical applications with React
Building Reliable Applications Using React, .NET & Azure
Session 03_04-Working with React Native.pptx
React suspense, not just for Alfred Hitchcock
React Lifecycle and Reconciliation
Building high performance web applications
Web Performance & Latest in React
Building high performance web applications
Building high performance web applications
Building reliable applications with React, C#, and Azure
React gsg presentation with ryan jung &amp; elias malik
0900 learning-react
Production-ready Next.js App with Cursor AI
react.pdf
Ad

More from Maurice De Beijer [MVP] (19)

PPTX
Full-stack App in half a Day: Next.js 15 Development Bootcamp
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
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
From zero to hero with the Reactive extensions for JavaScript
PPTX
From zero to hero with the reactive extensions for JavaScript
PPTX
Create flexible React applications using GraphQL apis
PPTX
Create flexible react applications using GraphQL API's
PPTX
Docker for a .NET web developer
PPTX
From zero to hero with the reactive extensions for JavaScript
PPTX
Docker containers on Windows
PPTX
Building high-performance web applications with Preact
PPTX
From zero to hero with the reactive extensions for java script
Full-stack App in half a Day: Next.js 15 Development Bootcamp
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
Why I am hooked on the future of React
Building reliable web applications using Cypress
Getting started with React Suspense and concurrent rendering
From zero to hero with the Reactive extensions for JavaScript
From zero to hero with the reactive extensions for JavaScript
Create flexible React applications using GraphQL apis
Create flexible react applications using GraphQL API's
Docker for a .NET web developer
From zero to hero with the reactive extensions for JavaScript
Docker containers on Windows
Building high-performance web applications with Preact
From zero to hero with the reactive extensions for java script

Recently uploaded (20)

PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Cloud computing and distributed systems.
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Unlocking AI with Model Context Protocol (MCP)
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Advanced Soft Computing BINUS July 2025.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
KodekX | Application Modernization Development
NewMind AI Weekly Chronicles - August'25 Week I
Cloud computing and distributed systems.
NewMind AI Monthly Chronicles - July 2025
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Dropbox Q2 2025 Financial Results & Investor Presentation
GamePlan Trading System Review: Professional Trader's Honest Take
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Unlocking AI with Model Context Protocol (MCP)
“AI and Expert System Decision Support & Business Intelligence Systems”
Advanced Soft Computing BINUS July 2025.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Spectral efficient network and resource selection model in 5G networks
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Understanding_Digital_Forensics_Presentation.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Review of recent advances in non-invasive hemoglobin estimation
KodekX | Application Modernization Development

The new React

Editor's Notes

  • #9: https://nodejs.org/ https://www.npmjs.com/ Welcome to the From Zero to Hero with ReactJS workshop. To prevent delays it would be helpful if you could prepare your laptop ahead of time. This way we won't be overloading the local WiFi connection when getting started.  There is not much needed to take part. But you will need to install NodeJS and NPM as a general dependency. To create the initial React application you will need to install Create-React-App. Use the command npm install --global create-react-app to do this. The biggest internet download is when you create the initial React application using Create-React-App. It would be helpful if you can create the initial project ahead of time. You can do this by opening a command prompt at a location where you would like the project to be on your hard drive. There execute the command create-react-app Nitflex. This will create a folder named Nitflex and add all required NPM packages to it. No time to do the setup? No need to worry about it, we will go through these steps during the workshop. With a  slow internet connection, this will take a bit of time but you will still be able to do everything.