SlideShare a Scribd company logo
WHAT/WHEN/WHY/HOW
ADVANCED REDUX -
Mateusz Bosek
Redux in three fundamental
principles:

Single source of truth
The global state of your
application is stored in an
object tree within a single
store.

State is read-only

The only way to change the
state is to emit an action, an
object describing what
happened.


Changes with pure
functions

Reducers are just pure
functions that take the
previous state and an
action, and return the next
state.
CQRS - Command Query
Responsibility Segregation

Commands

- command that performs an
action 


- change the state of the
system, but not return a value


Queries

- query that returns data to the
caller 


- return a result and do not change
the observable state of the system
React Context

Low-frequency updates like
locale, theme changes, user
authentication, etc.

Redux

Complex state management
which allows high-frequency
updates with full optimization
with a solid consistency
architecture
The context API with hooks
is much easier to
implement and will not
increase the app bundle
size.

It is a boilerplate and requires
a bunch of libraries. But it
remains a great solution
towards props drilling.



React Context
 Redux
WHO WINS?

For more complex state which has high-frequency
updates, the React Context won't be a good solution.
Because, the React Context will trigger a re-render on each
update, and optimizing it manually can be really tough
Advanced Redux architecture - WHAT/WHEN/WHY/HOW
Advanced Redux architecture - WHAT/WHEN/WHY/HOW
Advanced Redux architecture - WHAT/WHEN/WHY/HOW
Redux rules - Recommended
Write Action Types as domain/eventName

Write Actions Using the Flux Standard Action Convention

Use middlewares for Async Logic

Move Complex Logic Outside Components

Use Selector Functions to Read from Store State - (reselect)

Avoid Putting Form State In Redux*
Reduxrules-Strongrecommended


PutasMuchLogicasPossibleinReducers

ReducersShouldOwntheStateShape

NameStateSlicesBasedOntheStoredData

ModelActionsasEvents,NotSetters

WriteMeaningfulActionNames

AllowManyReducerstoRespondtotheSameAction

EvaluateWhereEachPieceofStateShouldLive

AvoidDispatchingManyActionsSequentially

ConnectMoreComponentstoReadDatafromtheStore

UsetheObjectShorthandFormofmapDispatchwithconnect
Redux rules - Essentials

Do Not Mutate State

Reducers Must Not Have Side Effects

Do Not Put Non-Serializable Values in State or Actions

Only One Redux Store Per App
1. Construction

Action types
2. Construction

Action creators
Events
Internal UI events


Notify a change


More than one handler

Commands
API calls


Invoke a procedure


One handler




Documents

Spread data


Transfer data


No reply, one reducer


2. Construction

Action categories
3. Action processing

Middlewares

Reducers
3. Action processing

Message routing patterns
3. Action processing

Message routing patterns

Filtering
function* watchFetchProducts() {

yield takeEvery('FETCH_PRODUCTS_REQUESTED', fetchProducts);

}
3. Action processing

Message routing patterns

Mapping
try {

const data = yield call(Api.fetchUser, action.payload.url)

yield put({ type: "FETCH_USERS_SUCCEEDED", data })

} catch (error) {

yield put({ type: "FETCH_USERS_FAILED", error })

}
3. Action processing

Message routing patterns

Splitting
if(action.type === “FETCH_POSTS_SUCCEEDED”) {

dispatch({ type: HIDE_LOADER });

dispatch({ type: DISPLAY_POSTS });

}
3.Actionprocessing

Messagetransformpatterns
3.Actionprocessing

Messagetransformpatterns

Enricher
if(action.type===“LOGIN_FORM_SUBMITTED”){

constdata={

...action.payload,

created:newDate()

};

next(data);

}
3.Actionprocessing

Messagetransformpatterns

Normalizer
if(action.type===“FETCH_USERS_SUCCEEDED”){

constpayload={...bigobject};


next(dispatch({type:DISPLAY_USERS, payload}));

}
3.Actionprocessing

Messagetransformpatterns

Translator
if(action.type===“FETCH_USERS_SUCCEEDED”){

dispatch({type:DISPLAY_USERS,payload});

dispatch({type:SET_PAGINATION,payload});

}
4. Middlewares

Redux-thunk

Redux-saga

Redux-observable


To take under consideration
1. Complexity

2. Coding Style

3. Learning Curve

4. Testability
WHY/WHEN TO USE REDUX



1. The same piece of application state needs to be mapped to
multiple container components.

2. Global components that can be accessed from anywhere

3. Too many props are being passed through multiple hierarchies of
components. 

4. State management using setState is bloating the component

5. Caching page state
mateusz.bosek@hubranch.com
Private and company consultation

THANK YOU

More Related Content

Similar to Advanced Redux architecture - WHAT/WHEN/WHY/HOW (20)

PDF
Redux essentials
Chandan Kumar Rana
 
PDF
Redux js
Nils Petersohn
 
PDF
How to Redux
Ted Pennings
 
PDF
Redux tutorial - intro to Redux by GetLittleTech
Oleg Kosuchin (GetLittleTech)
 
PPTX
Redux training
dasersoft
 
PDF
Redux Deep Dive - ReactFoo Pune 2018
Aziz Khambati
 
PPTX
Maintaining sanity in a large redux app
Nitish Kumar
 
PDF
Egghead redux-cheat-sheet-3-2-1
Augustin Bralley
 
PPTX
U3-02-React Redux and MUI.pptxaSDFGNXDASDFG
vinodkumarthatipamul
 
PDF
React Redux Tutorial | Redux Tutorial for Beginners | React Redux Training | ...
Edureka!
 
PPTX
Redux
Maulik Shah
 
PDF
Introduction to Redux (for Angular and React devs)
Fabio Biondi
 
PDF
Evan Schultz - Angular Summit - 2016
Evan Schultz
 
PDF
ReactRedux.pdf
Arsalan malik
 
PPTX
Modular development with redux
Javier Lafora Rey
 
PDF
Redux
Marco Lanaro
 
PDF
Understanding redux
David Atchley
 
PDF
React+Redux at Scale
C4Media
 
PPTX
Academy PRO: React JS. Redux & Tooling
Binary Studio
 
PDF
Building React Applications with Redux
FITC
 
Redux essentials
Chandan Kumar Rana
 
Redux js
Nils Petersohn
 
How to Redux
Ted Pennings
 
Redux tutorial - intro to Redux by GetLittleTech
Oleg Kosuchin (GetLittleTech)
 
Redux training
dasersoft
 
Redux Deep Dive - ReactFoo Pune 2018
Aziz Khambati
 
Maintaining sanity in a large redux app
Nitish Kumar
 
Egghead redux-cheat-sheet-3-2-1
Augustin Bralley
 
U3-02-React Redux and MUI.pptxaSDFGNXDASDFG
vinodkumarthatipamul
 
React Redux Tutorial | Redux Tutorial for Beginners | React Redux Training | ...
Edureka!
 
Introduction to Redux (for Angular and React devs)
Fabio Biondi
 
Evan Schultz - Angular Summit - 2016
Evan Schultz
 
ReactRedux.pdf
Arsalan malik
 
Modular development with redux
Javier Lafora Rey
 
Understanding redux
David Atchley
 
React+Redux at Scale
C4Media
 
Academy PRO: React JS. Redux & Tooling
Binary Studio
 
Building React Applications with Redux
FITC
 

Recently uploaded (20)

PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
July Patch Tuesday
Ivanti
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
July Patch Tuesday
Ivanti
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
Ad

Advanced Redux architecture - WHAT/WHEN/WHY/HOW