SlideShare a Scribd company logo
GLOBAL SOFTWARE CONSULTANCY
Plain React, Hooks and/or Redux?
Jörn Dinkla, jdinkla@thoughtworks.com
1
© 2020 ThoughtWorks
“... we encourage the use of vanilla React until you
experience enough pain points to justify bringing in
Redux”
Marc Garreau and Will Faurot, Authors of “Redux in Action”
2
© 2020 ThoughtWorks
Plain React
● Passing state as props
○ Large property lists
○ Unclear if data is really needed or just passed through
● Duplicate versions of data
○ What to update?
○ No single point of truth
● Original data vs. derived data is difficult to distinguish
○ E.g. from the database? Or from the FE?
○ (*) If we have to manipulate data in the FE is it BFF? BFW?
The pain points
3
State management
● One of the biggest problem of writing correct code
○ Without state you do not need context to understand code
○ With state you have to simulate the code and context to understand it
● Pure functional programming as remedy
● Or at least
○ state should be minimized
○ … and kept as local as possible
Problems with state
4
© 2019 ThoughtWorks
5
Plain react
Local state with React.Component
6
Plain react
Advantages
● Easy to learn
● Feels natural to OO developers
Disadvantages
● State is local, so has to be passed around (incl. getters/setters)
● Separation into presentation and container components is not enforced
● Tight coupling, if state manipulation is not a separate function
● Can be difficult to test and debug, no “replayability”
● State is decentralized, no overview
Using local state with React.Component
Hooks
Overview
7
[1] https://reactjs.org/docs/hooks-reference.html
Hooks
● const [getter, setter] = useState(initialValue)
● useEffect( () => fetch()..., [deps])
○ Replaces componentDidMount, componentDidUpdate, and
componentWillUnmount
○ Can return cleanup function
● const ctx = createContext(); … useContext(ctx)
● useReducer()
Restriction: top level of React FunctionComponents
Using local state with React.FunctionComponent
8
9
Hooks
Using local state with React.FunctionComponent
Advertisement from the React webpage
From https://reactjs.org/docs/hooks-intro.html#motivation
● “Hooks allow you to reuse stateful logic without changing your component
hierarchy”
● “Hooks let you split one component into smaller functions based on what
pieces are related (such as setting up a subscription or fetching data)”
● “Hooks let you use more of React’s features without classes”
● “Classes confuse both people and machines”
IMHO “very optimistic”
10
11
Hooks
Advantages
● Easy to learn
● “Hooks are a way to reuse stateful logic, not state itself.” [1]
Disadvantages
● State may still be local (when no context is used), so still has to be passed around
● Tight coupling, can be difficult to test, if not in separate functions
Using local state with React.FunctionComponent
[1] https://reactjs.org/docs/hooks-overview.html
12
Redux
Separation of concerns
A functional approach to state
13
14
Coupling between React and Redux
Good debugging support
Time travel included
15
© 2019 ThoughtWorks
16
Redux
A functional approach to state
Redux and testing
● Pure functions are easy to test
○ f(Input) = Output
● Stateful functions are more difficult to test
○ f(Input, State) = (Output, newState)
● [Stateful functions running concurrently are very difficult to test]
● Redux enforces functional programming with state
○ side effects only at certain defined places: action creators and middleware
● => So easy to test
17
18
Redux
Advantages
● Enforces separation of concerns
● Enforces explicit definitions (actions as types)
● Enforces Isolated points of state manipulation (reducers)
● Enforced structure improves testability
● Abstract executable model of your app without the view (store + actions)
● Not exclusive, hooks and local state may still be used
Disadvantages
● “Boilerplate” aka everything has to be defined explicitly
● Learning for devs
A functional approach to state
Proposal
19
© 2020 ThoughtWorks
Proposal
20
● Data with larger scope:
○ Use redux for the “backbone” of the data with larger scope
○ Reuse mapStateToProps/mapDispatchToProps
● Data with local scope
○ Use hooks
○ E.g. indices for dropdowns, temporary changes
Ad

Recommended

Redux in Angular 2+
Redux in Angular 2+
Hùng Nguyễn Huy
 
Fabio Biondi - Front-end data architectures in Angular, Redux & NGRX - Codemo...
Fabio Biondi - Front-end data architectures in Angular, Redux & NGRX - Codemo...
Codemotion
 
Do and Don't summary of React Component Lifecycle Methods
Do and Don't summary of React Component Lifecycle Methods
Sunil Mishra
 
Getting Started with NgRx (Redux) Angular
Getting Started with NgRx (Redux) Angular
Gustavo Costa
 
React redux-redux-saga-rahil-memon
React redux-redux-saga-rahil-memon
RahilMemon5
 
Redux essentials
Redux essentials
Chandan Kumar Rana
 
Academy PRO: Advanced React Ecosystem. MobX
Academy PRO: Advanced React Ecosystem. MobX
Binary Studio
 
Redux workshop
Redux workshop
Imran Sayed
 
Understanding React hooks | Walkingtree Technologies
Understanding React hooks | Walkingtree Technologies
Walking Tree Technologies
 
Introduction to Redux.pptx
Introduction to Redux.pptx
MohammadImran322154
 
Why Concurrency is hard ?
Why Concurrency is hard ?
Ramith Jayasinghe
 
Understanding react hooks
Understanding react hooks
Samundra khatri
 
Concurrency - Why it's hard ?
Concurrency - Why it's hard ?
Ramith Jayasinghe
 
FRONTEND BOOTCAMP 4.pptx
FRONTEND BOOTCAMP 4.pptx
Ehtesham46
 
React workshop
React workshop
Imran Sayed
 
an Introduction to Redux
an Introduction to Redux
Amin Ashtiani
 
STATE MANAGEMENT IN REACT [Autosaved].pptx
STATE MANAGEMENT IN REACT [Autosaved].pptx
siddheshjadhav919123
 
FRU Kathmandu: Adopting with Change Frontend Architecture and Patterns
FRU Kathmandu: Adopting with Change Frontend Architecture and Patterns
Leapfrog Technology Inc.
 
Fundamental concepts of react js
Fundamental concepts of react js
StephieJohn
 
"The Story of Declarative React at Grammarly: From two-way data binding with ...
"The Story of Declarative React at Grammarly: From two-way data binding with ...
Fwdays
 
20 React Interview Questions. Pdf Download
20 React Interview Questions. Pdf Download
Mohd Quasim
 
React
React
Amitai Barnea
 
100 React Interview questions 2024.pptx.pdf
100 React Interview questions 2024.pptx.pdf
codevincent624
 
React Interview Question PDF By ScholarHat
React Interview Question PDF By ScholarHat
Scholarhat
 
React Workshop: Core concepts of react
React Workshop: Core concepts of react
Imran Sayed
 
Green Custard Friday Talk 21: React Hooks
Green Custard Friday Talk 21: React Hooks
Green Custard
 
The Road To Redux
The Road To Redux
Jeffrey Sanchez
 
React learning in the hard way
React learning in the hard way
Chen Feldman
 
Presentation of the book "Mikado Method"
Presentation of the book "Mikado Method"
Jörn Dinkla
 
Korrekte nebenläufige Anwendungen mit Koroutinen und TDD
Korrekte nebenläufige Anwendungen mit Koroutinen und TDD
Jörn Dinkla
 

More Related Content

Similar to Plain react, hooks and/or Redux ? (20)

Understanding React hooks | Walkingtree Technologies
Understanding React hooks | Walkingtree Technologies
Walking Tree Technologies
 
Introduction to Redux.pptx
Introduction to Redux.pptx
MohammadImran322154
 
Why Concurrency is hard ?
Why Concurrency is hard ?
Ramith Jayasinghe
 
Understanding react hooks
Understanding react hooks
Samundra khatri
 
Concurrency - Why it's hard ?
Concurrency - Why it's hard ?
Ramith Jayasinghe
 
FRONTEND BOOTCAMP 4.pptx
FRONTEND BOOTCAMP 4.pptx
Ehtesham46
 
React workshop
React workshop
Imran Sayed
 
an Introduction to Redux
an Introduction to Redux
Amin Ashtiani
 
STATE MANAGEMENT IN REACT [Autosaved].pptx
STATE MANAGEMENT IN REACT [Autosaved].pptx
siddheshjadhav919123
 
FRU Kathmandu: Adopting with Change Frontend Architecture and Patterns
FRU Kathmandu: Adopting with Change Frontend Architecture and Patterns
Leapfrog Technology Inc.
 
Fundamental concepts of react js
Fundamental concepts of react js
StephieJohn
 
"The Story of Declarative React at Grammarly: From two-way data binding with ...
"The Story of Declarative React at Grammarly: From two-way data binding with ...
Fwdays
 
20 React Interview Questions. Pdf Download
20 React Interview Questions. Pdf Download
Mohd Quasim
 
React
React
Amitai Barnea
 
100 React Interview questions 2024.pptx.pdf
100 React Interview questions 2024.pptx.pdf
codevincent624
 
React Interview Question PDF By ScholarHat
React Interview Question PDF By ScholarHat
Scholarhat
 
React Workshop: Core concepts of react
React Workshop: Core concepts of react
Imran Sayed
 
Green Custard Friday Talk 21: React Hooks
Green Custard Friday Talk 21: React Hooks
Green Custard
 
The Road To Redux
The Road To Redux
Jeffrey Sanchez
 
React learning in the hard way
React learning in the hard way
Chen Feldman
 
Understanding React hooks | Walkingtree Technologies
Understanding React hooks | Walkingtree Technologies
Walking Tree Technologies
 
Understanding react hooks
Understanding react hooks
Samundra khatri
 
Concurrency - Why it's hard ?
Concurrency - Why it's hard ?
Ramith Jayasinghe
 
FRONTEND BOOTCAMP 4.pptx
FRONTEND BOOTCAMP 4.pptx
Ehtesham46
 
an Introduction to Redux
an Introduction to Redux
Amin Ashtiani
 
STATE MANAGEMENT IN REACT [Autosaved].pptx
STATE MANAGEMENT IN REACT [Autosaved].pptx
siddheshjadhav919123
 
FRU Kathmandu: Adopting with Change Frontend Architecture and Patterns
FRU Kathmandu: Adopting with Change Frontend Architecture and Patterns
Leapfrog Technology Inc.
 
Fundamental concepts of react js
Fundamental concepts of react js
StephieJohn
 
"The Story of Declarative React at Grammarly: From two-way data binding with ...
"The Story of Declarative React at Grammarly: From two-way data binding with ...
Fwdays
 
20 React Interview Questions. Pdf Download
20 React Interview Questions. Pdf Download
Mohd Quasim
 
100 React Interview questions 2024.pptx.pdf
100 React Interview questions 2024.pptx.pdf
codevincent624
 
React Interview Question PDF By ScholarHat
React Interview Question PDF By ScholarHat
Scholarhat
 
React Workshop: Core concepts of react
React Workshop: Core concepts of react
Imran Sayed
 
Green Custard Friday Talk 21: React Hooks
Green Custard Friday Talk 21: React Hooks
Green Custard
 
React learning in the hard way
React learning in the hard way
Chen Feldman
 

More from Jörn Dinkla (18)

Presentation of the book "Mikado Method"
Presentation of the book "Mikado Method"
Jörn Dinkla
 
Korrekte nebenläufige Anwendungen mit Koroutinen und TDD
Korrekte nebenläufige Anwendungen mit Koroutinen und TDD
Jörn Dinkla
 
Nebenlaeufigkeit mit Koroutinen strukturieren
Nebenlaeufigkeit mit Koroutinen strukturieren
Jörn Dinkla
 
A short introduction to Kotlin
A short introduction to Kotlin
Jörn Dinkla
 
Concurrency in Kotlin with coroutines
Concurrency in Kotlin with coroutines
Jörn Dinkla
 
Nebenläufigkeit mit Kotlins Koroutinen
Nebenläufigkeit mit Kotlins Koroutinen
Jörn Dinkla
 
GPU-Computing mit CUDA und OpenCL
GPU-Computing mit CUDA und OpenCL
Jörn Dinkla
 
Schulung: Einführung in das GPU-Computing mit NVIDIA CUDA
Schulung: Einführung in das GPU-Computing mit NVIDIA CUDA
Jörn Dinkla
 
Die ‚komplexe‘ Perspektive - Einführung in die digitale Wirtschaft
Die ‚komplexe‘ Perspektive - Einführung in die digitale Wirtschaft
Jörn Dinkla
 
Geschäftsmodelle - Ein kurzer Überblick
Geschäftsmodelle - Ein kurzer Überblick
Jörn Dinkla
 
Buchvorstellung "Libertarian Anarchy: Against the State" von Gerard Casey
Buchvorstellung "Libertarian Anarchy: Against the State" von Gerard Casey
Jörn Dinkla
 
Multi-GPU-Computing: Eins, zwei, drei, ganz viele
Multi-GPU-Computing: Eins, zwei, drei, ganz viele
Jörn Dinkla
 
Tipps & Tricks für den erfolgreichen Einsatz von GPU-Computing
Tipps & Tricks für den erfolgreichen Einsatz von GPU-Computing
Jörn Dinkla
 
GPU-Computing mit CUDA und OpenCL in der Praxis
GPU-Computing mit CUDA und OpenCL in der Praxis
Jörn Dinkla
 
Introduction To Parallel Computing
Introduction To Parallel Computing
Jörn Dinkla
 
Subversion Schulung
Subversion Schulung
Jörn Dinkla
 
Test-Driven-Development mit JUnit 4
Test-Driven-Development mit JUnit 4
Jörn Dinkla
 
Ant im Detail
Ant im Detail
Jörn Dinkla
 
Presentation of the book "Mikado Method"
Presentation of the book "Mikado Method"
Jörn Dinkla
 
Korrekte nebenläufige Anwendungen mit Koroutinen und TDD
Korrekte nebenläufige Anwendungen mit Koroutinen und TDD
Jörn Dinkla
 
Nebenlaeufigkeit mit Koroutinen strukturieren
Nebenlaeufigkeit mit Koroutinen strukturieren
Jörn Dinkla
 
A short introduction to Kotlin
A short introduction to Kotlin
Jörn Dinkla
 
Concurrency in Kotlin with coroutines
Concurrency in Kotlin with coroutines
Jörn Dinkla
 
Nebenläufigkeit mit Kotlins Koroutinen
Nebenläufigkeit mit Kotlins Koroutinen
Jörn Dinkla
 
GPU-Computing mit CUDA und OpenCL
GPU-Computing mit CUDA und OpenCL
Jörn Dinkla
 
Schulung: Einführung in das GPU-Computing mit NVIDIA CUDA
Schulung: Einführung in das GPU-Computing mit NVIDIA CUDA
Jörn Dinkla
 
Die ‚komplexe‘ Perspektive - Einführung in die digitale Wirtschaft
Die ‚komplexe‘ Perspektive - Einführung in die digitale Wirtschaft
Jörn Dinkla
 
Geschäftsmodelle - Ein kurzer Überblick
Geschäftsmodelle - Ein kurzer Überblick
Jörn Dinkla
 
Buchvorstellung "Libertarian Anarchy: Against the State" von Gerard Casey
Buchvorstellung "Libertarian Anarchy: Against the State" von Gerard Casey
Jörn Dinkla
 
Multi-GPU-Computing: Eins, zwei, drei, ganz viele
Multi-GPU-Computing: Eins, zwei, drei, ganz viele
Jörn Dinkla
 
Tipps & Tricks für den erfolgreichen Einsatz von GPU-Computing
Tipps & Tricks für den erfolgreichen Einsatz von GPU-Computing
Jörn Dinkla
 
GPU-Computing mit CUDA und OpenCL in der Praxis
GPU-Computing mit CUDA und OpenCL in der Praxis
Jörn Dinkla
 
Introduction To Parallel Computing
Introduction To Parallel Computing
Jörn Dinkla
 
Subversion Schulung
Subversion Schulung
Jörn Dinkla
 
Test-Driven-Development mit JUnit 4
Test-Driven-Development mit JUnit 4
Jörn Dinkla
 
Ad

Recently uploaded (20)

Decipher SEO Solutions for your startup needs.
Decipher SEO Solutions for your startup needs.
mathai2
 
Canva Pro Crack Free Download 2025-FREE LATEST
Canva Pro Crack Free Download 2025-FREE LATEST
grete1122g
 
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
 
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
 
Zoho Creator Solution for EI by Elsner Technologies.docx
Zoho Creator Solution for EI by Elsner Technologies.docx
Elsner Technologies Pvt. Ltd.
 
Why Edge Computing Matters in Mobile Application Tech.pdf
Why Edge Computing Matters in Mobile Application Tech.pdf
IMG Global Infotech
 
From Code to Commerce, a Backend Java Developer's Galactic Journey into Ecomm...
From Code to Commerce, a Backend Java Developer's Galactic Journey into Ecomm...
Jamie Coleman
 
Modern Platform Engineering with Choreo - The AI-Native Internal Developer Pl...
Modern Platform Engineering with Choreo - The AI-Native Internal Developer Pl...
WSO2
 
From Data Preparation to Inference: How Alluxio Speeds Up AI
From Data Preparation to Inference: How Alluxio Speeds Up AI
Alluxio, Inc.
 
HYBRIDIZATION OF ALKANES AND ALKENES ...
HYBRIDIZATION OF ALKANES AND ALKENES ...
karishmaduhijod1
 
Heat Treatment Process Automation in India
Heat Treatment Process Automation in India
Reckers Mechatronics
 
Azure AI Foundry: The AI app and agent factory
Azure AI Foundry: The AI app and agent factory
Maxim Salnikov
 
Streamlining CI/CD with FME Flow: A Practical Guide
Streamlining CI/CD with FME Flow: A Practical Guide
Safe Software
 
Enable Your Cloud Journey With Microsoft Trusted Partner | IFI Tech
Enable Your Cloud Journey With Microsoft Trusted Partner | IFI Tech
IFI Techsolutions
 
Test Case Design Techniques – Practical Examples & Best Practices in Software...
Test Case Design Techniques – Practical Examples & Best Practices in Software...
Muhammad Fahad Bashir
 
Threat Modeling a Batch Job Framework - Teri Radichel - AWS re:Inforce 2025
Threat Modeling a Batch Job Framework - Teri Radichel - AWS re:Inforce 2025
2nd Sight Lab
 
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
 
Humans vs AI Call Agents - Qcall.ai's Special Report
Humans vs AI Call Agents - Qcall.ai's Special Report
Udit Goenka
 
Building Geospatial Data Warehouse for GIS by GIS with FME
Building Geospatial Data Warehouse for GIS by GIS with FME
Safe Software
 
Simplify Task, Team, and Project Management with Orangescrum Work
Simplify Task, Team, and Project Management with Orangescrum Work
Orangescrum
 
Decipher SEO Solutions for your startup needs.
Decipher SEO Solutions for your startup needs.
mathai2
 
Canva Pro Crack Free Download 2025-FREE LATEST
Canva Pro Crack Free Download 2025-FREE LATEST
grete1122g
 
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
 
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
 
Zoho Creator Solution for EI by Elsner Technologies.docx
Zoho Creator Solution for EI by Elsner Technologies.docx
Elsner Technologies Pvt. Ltd.
 
Why Edge Computing Matters in Mobile Application Tech.pdf
Why Edge Computing Matters in Mobile Application Tech.pdf
IMG Global Infotech
 
From Code to Commerce, a Backend Java Developer's Galactic Journey into Ecomm...
From Code to Commerce, a Backend Java Developer's Galactic Journey into Ecomm...
Jamie Coleman
 
Modern Platform Engineering with Choreo - The AI-Native Internal Developer Pl...
Modern Platform Engineering with Choreo - The AI-Native Internal Developer Pl...
WSO2
 
From Data Preparation to Inference: How Alluxio Speeds Up AI
From Data Preparation to Inference: How Alluxio Speeds Up AI
Alluxio, Inc.
 
HYBRIDIZATION OF ALKANES AND ALKENES ...
HYBRIDIZATION OF ALKANES AND ALKENES ...
karishmaduhijod1
 
Heat Treatment Process Automation in India
Heat Treatment Process Automation in India
Reckers Mechatronics
 
Azure AI Foundry: The AI app and agent factory
Azure AI Foundry: The AI app and agent factory
Maxim Salnikov
 
Streamlining CI/CD with FME Flow: A Practical Guide
Streamlining CI/CD with FME Flow: A Practical Guide
Safe Software
 
Enable Your Cloud Journey With Microsoft Trusted Partner | IFI Tech
Enable Your Cloud Journey With Microsoft Trusted Partner | IFI Tech
IFI Techsolutions
 
Test Case Design Techniques – Practical Examples & Best Practices in Software...
Test Case Design Techniques – Practical Examples & Best Practices in Software...
Muhammad Fahad Bashir
 
Threat Modeling a Batch Job Framework - Teri Radichel - AWS re:Inforce 2025
Threat Modeling a Batch Job Framework - Teri Radichel - AWS re:Inforce 2025
2nd Sight Lab
 
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
 
Humans vs AI Call Agents - Qcall.ai's Special Report
Humans vs AI Call Agents - Qcall.ai's Special Report
Udit Goenka
 
Building Geospatial Data Warehouse for GIS by GIS with FME
Building Geospatial Data Warehouse for GIS by GIS with FME
Safe Software
 
Simplify Task, Team, and Project Management with Orangescrum Work
Simplify Task, Team, and Project Management with Orangescrum Work
Orangescrum
 
Ad

Plain react, hooks and/or Redux ?

  • 1. GLOBAL SOFTWARE CONSULTANCY Plain React, Hooks and/or Redux? Jörn Dinkla, [email protected] 1 © 2020 ThoughtWorks
  • 2. “... we encourage the use of vanilla React until you experience enough pain points to justify bringing in Redux” Marc Garreau and Will Faurot, Authors of “Redux in Action” 2 © 2020 ThoughtWorks
  • 3. Plain React ● Passing state as props ○ Large property lists ○ Unclear if data is really needed or just passed through ● Duplicate versions of data ○ What to update? ○ No single point of truth ● Original data vs. derived data is difficult to distinguish ○ E.g. from the database? Or from the FE? ○ (*) If we have to manipulate data in the FE is it BFF? BFW? The pain points 3
  • 4. State management ● One of the biggest problem of writing correct code ○ Without state you do not need context to understand code ○ With state you have to simulate the code and context to understand it ● Pure functional programming as remedy ● Or at least ○ state should be minimized ○ … and kept as local as possible Problems with state 4 © 2019 ThoughtWorks
  • 5. 5 Plain react Local state with React.Component
  • 6. 6 Plain react Advantages ● Easy to learn ● Feels natural to OO developers Disadvantages ● State is local, so has to be passed around (incl. getters/setters) ● Separation into presentation and container components is not enforced ● Tight coupling, if state manipulation is not a separate function ● Can be difficult to test and debug, no “replayability” ● State is decentralized, no overview Using local state with React.Component
  • 8. Hooks ● const [getter, setter] = useState(initialValue) ● useEffect( () => fetch()..., [deps]) ○ Replaces componentDidMount, componentDidUpdate, and componentWillUnmount ○ Can return cleanup function ● const ctx = createContext(); … useContext(ctx) ● useReducer() Restriction: top level of React FunctionComponents Using local state with React.FunctionComponent 8
  • 9. 9 Hooks Using local state with React.FunctionComponent
  • 10. Advertisement from the React webpage From https://reactjs.org/docs/hooks-intro.html#motivation ● “Hooks allow you to reuse stateful logic without changing your component hierarchy” ● “Hooks let you split one component into smaller functions based on what pieces are related (such as setting up a subscription or fetching data)” ● “Hooks let you use more of React’s features without classes” ● “Classes confuse both people and machines” IMHO “very optimistic” 10
  • 11. 11 Hooks Advantages ● Easy to learn ● “Hooks are a way to reuse stateful logic, not state itself.” [1] Disadvantages ● State may still be local (when no context is used), so still has to be passed around ● Tight coupling, can be difficult to test, if not in separate functions Using local state with React.FunctionComponent [1] https://reactjs.org/docs/hooks-overview.html
  • 12. 12 Redux Separation of concerns A functional approach to state
  • 13. 13
  • 15. Good debugging support Time travel included 15 © 2019 ThoughtWorks
  • 17. Redux and testing ● Pure functions are easy to test ○ f(Input) = Output ● Stateful functions are more difficult to test ○ f(Input, State) = (Output, newState) ● [Stateful functions running concurrently are very difficult to test] ● Redux enforces functional programming with state ○ side effects only at certain defined places: action creators and middleware ● => So easy to test 17
  • 18. 18 Redux Advantages ● Enforces separation of concerns ● Enforces explicit definitions (actions as types) ● Enforces Isolated points of state manipulation (reducers) ● Enforced structure improves testability ● Abstract executable model of your app without the view (store + actions) ● Not exclusive, hooks and local state may still be used Disadvantages ● “Boilerplate” aka everything has to be defined explicitly ● Learning for devs A functional approach to state
  • 20. Proposal 20 ● Data with larger scope: ○ Use redux for the “backbone” of the data with larger scope ○ Reuse mapStateToProps/mapDispatchToProps ● Data with local scope ○ Use hooks ○ E.g. indices for dropdowns, temporary changes