SlideShare a Scribd company logo
SIX MONTHS OF REACT & REDUX:
A REAL WORLD USE CASE
Thom Nichols - @thom_nic
DISCLAIMER:
 Not an expert
 I might be doing it wrong
SO YOU WANT TO TRY REACT +
REDUX…
WHAT ARE YOU (PROBABLY) GOING TO
NEED?
 Webpack
 Babel + presets
 React-redux
 Redux-thunk
 Redux-logger
 Axios or fetch-polyfill
 Immutable.js
 React
 Redux
 Jest or Mocha + JSDOM or Karma + Phantomjs
 React-router
 React-router-redux
ALL YOU NEED IS A FEW PACKAGES
FROM NPM
GREAT! AM I READY TO START
PROGRAMMING NOW?
WHAT ARE YOU (PROBABLY) GOING TO
NEED?
 Webpack
 Babel + presets
 React-redux
 Redux-thunk
 Redux-logger
 Axios or fetch-polyfill
 Immutable.js
 React
 Redux
 Jest or Mocha + JSDOM or Karma + Phantomjs
 React-router
 React-router-redux
What we actually
care about
WHAT ARE YOU (PROBABLY) GOING TO
NEED?
 Webpack
 Babel + presets
 React-redux
 Redux-thunk
 Redux-logger
 Axios or fetch-polyfill
 Immutable.js
 React
 Redux
 Jest or Mocha + JSDOM or Karma + Phantomjs
 React-router
 React-router-redux
What we actually
care about
LET’S TALK ABOUT REDUX
FLUX ARCHITECTURE
FLUX ARCHITECTURE - SIMPLIFIED
SHOW ME THE CODE!
TRIVIAL ACTION EXAMPLE
store.dispatch( addTodo(‘call mom’) );
TRIVIAL REDUCER EXAMPLE
THINGS NOBODY TOLD ME ABOUT
REACT + REDUX
USE IMMUTABLE.JS RECORDS!
 Without Records:
 With Records:
USE IMMUTABLE.JS RECORDS!
WHAT SHOULD MY STORES HOLD?
WHAT DOES MY DATA LOOK LIKE?
MY STORES HOLD MAPS
STORES MAY LISTEN TO “OTHER”
ACTIONS
I’M IN UR COMPONENT…
CONNECTIN UR PROPS
ACTIONS + PROMISE CHAINING =
AWESOME
ACTIONS + PROMISE CHAINING =
AWESOME
WHAT’S ANNOYING?
 Component testing connected components is hard.
I rely (mostly) on functional testing
 Export both a connect()-ed and non-connected component
 See: Erik Ras’ “ducks”
WHAT’S ANNOYING?
 It’s difficult to call a method on a component wrapped as a high-order
component…
DON’T DO IT
 BUT: you probably shouldn’t be doing that anyway:
 pass data via callbacks passed from parent component.
 Or pass data via a redux action
LET’S RECAP
 Use ImmutableJS records for domain types in stores
 Use ImmutableJS Maps often for store data containers
 Use redux-thunk to make remote requests in actions
 Async action creators should always return a promise
 Reducer cases are not always 1-to-1 with actions
 Let me know if you’ve figured out the component testing issue with
connected components…
 HoC component wrapping cause some pain
 Webpack is really the most annoying part
MORE TRICKS
DEBOUNCE EXPENSIVE ACTIONS
 Some independent top-level components say what data they want to
fetch from `componentWillMount()`
 Debounce  a single remote request
CONSISTENTLY DISPATCH START & END
ACTIONS
 These are used for loading indicator & error messaging
BONUS: REDUX-FORM IS AWESOME
BONUS: REDUX-FORM IS AWESOME
DECIDE WHAT WORKS FOR YOU
Frameworks are less about prescribing “the
right way” and more about getting everyone
to do things the same way.
- @thom_nic
THANKS
ACTUALLY….
ASK ME ABOUT DIGITAL ELECTRICITY
MORE SLIDES
I DON’T NEED ANGULAR-RESOURCE
 This is actually (really) boilerplate. Replaced with this:
WHY I DON’T NEED ANGULAR-
RESOURCE
 … and http thunks of thunks:
A WORD TO THE WISE…
 Avoid temptation to do client-side data manipulation to attempt to
mirror server state.
 Better to always fetch from the server as the source of truth

More Related Content

What's hot (20)

PDF
React & Redux
Federico Bond
 
PDF
React state managmenet with Redux
Vedran Blaženka
 
PPTX
Getting started with Redux js
Citrix
 
PDF
React.js and Redux overview
Alex Bachuk
 
PPTX
Academy PRO: React JS. Redux & Tooling
Binary Studio
 
PDF
Introduction to Redux
Ignacio Martín
 
PPTX
React, Flux and a little bit of Redux
Ny Fanilo Andrianjafy, B.Eng.
 
PDF
Using redux
Jonas Ohlsson Aden
 
PPTX
React / Redux Architectures
Vinícius Ribeiro
 
PDF
Introduction to React & Redux
Boris Dinkevich
 
PPTX
Redux training
dasersoft
 
PDF
React, Redux, ES2015 by Max Petruck
Maksym Petruk
 
PPTX
Better web apps with React and Redux
Ali Sa'o
 
PPTX
React & redux
Cédric Hartland
 
PPTX
React + Redux Introduction
Nikolaus Graf
 
PPTX
React + Redux + TypeScript === ♥
Remo Jansen
 
PDF
React JS and Redux
Glib Kechyn
 
PDF
Switch to React.js from AngularJS developer
Eugene Zharkov
 
PDF
React Lifecycle and Reconciliation
Zhihao Li
 
PDF
An Introduction to ReactJS
All Things Open
 
React & Redux
Federico Bond
 
React state managmenet with Redux
Vedran Blaženka
 
Getting started with Redux js
Citrix
 
React.js and Redux overview
Alex Bachuk
 
Academy PRO: React JS. Redux & Tooling
Binary Studio
 
Introduction to Redux
Ignacio Martín
 
React, Flux and a little bit of Redux
Ny Fanilo Andrianjafy, B.Eng.
 
Using redux
Jonas Ohlsson Aden
 
React / Redux Architectures
Vinícius Ribeiro
 
Introduction to React & Redux
Boris Dinkevich
 
Redux training
dasersoft
 
React, Redux, ES2015 by Max Petruck
Maksym Petruk
 
Better web apps with React and Redux
Ali Sa'o
 
React & redux
Cédric Hartland
 
React + Redux Introduction
Nikolaus Graf
 
React + Redux + TypeScript === ♥
Remo Jansen
 
React JS and Redux
Glib Kechyn
 
Switch to React.js from AngularJS developer
Eugene Zharkov
 
React Lifecycle and Reconciliation
Zhihao Li
 
An Introduction to ReactJS
All Things Open
 

Viewers also liked (6)

PDF
Async Server Rendering in React+Redux at NYTimes (redux-taxi)
Jeremy Gayed
 
PPTX
Mongo for the Mission Critical Enterprise
MongoDB
 
PPTX
Async Redux Actions With RxJS - React Rally 2016
Ben Lesh
 
PDF
RxJS + Redux + React = Amazing
Jay Phelps
 
PPTX
RxJS and Reactive Programming - Modern Web UI - May 2015
Ben Lesh
 
PPT
React js
Jai Santhosh
 
Async Server Rendering in React+Redux at NYTimes (redux-taxi)
Jeremy Gayed
 
Mongo for the Mission Critical Enterprise
MongoDB
 
Async Redux Actions With RxJS - React Rally 2016
Ben Lesh
 
RxJS + Redux + React = Amazing
Jay Phelps
 
RxJS and Reactive Programming - Modern Web UI - May 2015
Ben Lesh
 
React js
Jai Santhosh
 
Ad

Similar to ProvJS: Six Months of ReactJS and Redux (20)

PDF
The History of React-Hot-Loader
Anton Korzunov
 
PPTX
Ultimate Survival - React-Native edition
Richard Radics
 
PDF
Learning React js Learn React JS From Scratch with Hands On Projects 2nd Edit...
bandmvh3697
 
PDF
Universal React apps in Next.js
🐕 Łukasz Ostrowski
 
PDF
Introduction to ReactJS and Redux
Boris Dinkevich
 
PDF
Using Docker in the Real World
Tim Haak
 
PDF
Create ReactJS Component & publish as npm package
Andrii Lundiak
 
PDF
A React Journey
LinkMe Srl
 
PDF
Ryan Christiani I Heard React Was Good
FITC
 
PDF
Matheus Marsiglio - Isomorphic React + Redux App
React Conf Brasil
 
PDF
React Native +Redux + ES6 (Updated)
Chiew Carol
 
PDF
Performance
Varnish Software
 
PDF
A Practical Approach to React Native at All Things Open Conference
Tracy Lee
 
PPTX
Do you queue (updated)
10n Software, LLC
 
PPTX
React gsg presentation with ryan jung & elias malik
Lama K Banna
 
PPTX
React js programming concept
Tariqul islam
 
PPTX
Adding a modern twist to legacy web applications
Jeff Durta
 
PDF
Aura LA GDG - July 17-2017
Kristan Uccello
 
PDF
The Mysteries Of JavaScript-Fu (RailsConf Ediition)
danwrong
 
The History of React-Hot-Loader
Anton Korzunov
 
Ultimate Survival - React-Native edition
Richard Radics
 
Learning React js Learn React JS From Scratch with Hands On Projects 2nd Edit...
bandmvh3697
 
Universal React apps in Next.js
🐕 Łukasz Ostrowski
 
Introduction to ReactJS and Redux
Boris Dinkevich
 
Using Docker in the Real World
Tim Haak
 
Create ReactJS Component & publish as npm package
Andrii Lundiak
 
A React Journey
LinkMe Srl
 
Ryan Christiani I Heard React Was Good
FITC
 
Matheus Marsiglio - Isomorphic React + Redux App
React Conf Brasil
 
React Native +Redux + ES6 (Updated)
Chiew Carol
 
Performance
Varnish Software
 
A Practical Approach to React Native at All Things Open Conference
Tracy Lee
 
Do you queue (updated)
10n Software, LLC
 
React gsg presentation with ryan jung & elias malik
Lama K Banna
 
React js programming concept
Tariqul islam
 
Adding a modern twist to legacy web applications
Jeff Durta
 
Aura LA GDG - July 17-2017
Kristan Uccello
 
The Mysteries Of JavaScript-Fu (RailsConf Ediition)
danwrong
 
Ad

Recently uploaded (20)

PDF
Troubleshooting Virtual Threads in Java!
Tier1 app
 
PDF
How Agentic AI Networks are Revolutionizing Collaborative AI Ecosystems in 2025
ronakdubey419
 
PPTX
Presentation about variables and constant.pptx
kr2589474
 
PPTX
Farrell__10e_ch04_PowerPoint.pptx Programming Logic and Design slides
bashnahara11
 
PPTX
GALILEO CRS SYSTEM | GALILEO TRAVEL SOFTWARE
philipnathen82
 
PDF
Using licensed Data Loss Prevention (DLP) as a strategic proactive data secur...
Q-Advise
 
PDF
SAP GUI Installation Guide for Windows | Step-by-Step Setup for SAP Access
SAP Vista, an A L T Z E N Company
 
PDF
What companies do with Pharo (ESUG 2025)
ESUG
 
PDF
Generating Union types w/ Static Analysis
K. Matthew Dupree
 
PDF
Salesforce Pricing Update 2025: Impact, Strategy & Smart Cost Optimization wi...
GetOnCRM Solutions
 
PPT
Brief History of Python by Learning Python in three hours
adanechb21
 
PDF
WatchTraderHub - Watch Dealer software with inventory management and multi-ch...
WatchDealer Pavel
 
PPTX
Presentation about Database and Database Administrator
abhishekchauhan86963
 
PDF
Supabase Meetup: Build in a weekend, scale to millions
Carlo Gilmar Padilla Santana
 
PDF
System Center 2025 vs. 2022; What’s new, what’s next_PDF.pdf
Q-Advise
 
PDF
10 posting ideas for community engagement with AI prompts
Pankaj Taneja
 
PDF
Summary Of Odoo 18.1 to 18.4 : The Way For Odoo 19
CandidRoot Solutions Private Limited
 
PDF
AWS_Agentic_AI_in_Indian_BFSI_A_Strategic_Blueprint_for_Customer.pdf
siddharthnetsavvies
 
PDF
Step-by-Step Guide to Install SAP HANA Studio | Complete Installation Tutoria...
SAP Vista, an A L T Z E N Company
 
PPTX
classification of computer and basic part of digital computer
ravisinghrajpurohit3
 
Troubleshooting Virtual Threads in Java!
Tier1 app
 
How Agentic AI Networks are Revolutionizing Collaborative AI Ecosystems in 2025
ronakdubey419
 
Presentation about variables and constant.pptx
kr2589474
 
Farrell__10e_ch04_PowerPoint.pptx Programming Logic and Design slides
bashnahara11
 
GALILEO CRS SYSTEM | GALILEO TRAVEL SOFTWARE
philipnathen82
 
Using licensed Data Loss Prevention (DLP) as a strategic proactive data secur...
Q-Advise
 
SAP GUI Installation Guide for Windows | Step-by-Step Setup for SAP Access
SAP Vista, an A L T Z E N Company
 
What companies do with Pharo (ESUG 2025)
ESUG
 
Generating Union types w/ Static Analysis
K. Matthew Dupree
 
Salesforce Pricing Update 2025: Impact, Strategy & Smart Cost Optimization wi...
GetOnCRM Solutions
 
Brief History of Python by Learning Python in three hours
adanechb21
 
WatchTraderHub - Watch Dealer software with inventory management and multi-ch...
WatchDealer Pavel
 
Presentation about Database and Database Administrator
abhishekchauhan86963
 
Supabase Meetup: Build in a weekend, scale to millions
Carlo Gilmar Padilla Santana
 
System Center 2025 vs. 2022; What’s new, what’s next_PDF.pdf
Q-Advise
 
10 posting ideas for community engagement with AI prompts
Pankaj Taneja
 
Summary Of Odoo 18.1 to 18.4 : The Way For Odoo 19
CandidRoot Solutions Private Limited
 
AWS_Agentic_AI_in_Indian_BFSI_A_Strategic_Blueprint_for_Customer.pdf
siddharthnetsavvies
 
Step-by-Step Guide to Install SAP HANA Studio | Complete Installation Tutoria...
SAP Vista, an A L T Z E N Company
 
classification of computer and basic part of digital computer
ravisinghrajpurohit3
 

ProvJS: Six Months of ReactJS and Redux

Editor's Notes

  • #3: What I’m going to present seems to be working OK for me. It might not work for you. Try it yourself and decide.
  • #4: • How many people have written a simple redux app? • How many people have read some tutorials? So you’ve heard redux is pretty rad. Lots of people say it’s cool. Maybe you’ve used Angular or Ember or Backbone and Marionette. Well, react is like that, except….
  • #5: Also react-router and redux-simple-router. Also hot module reloading. And the source maps. Never forget the source maps. You might spend a week getting those two things working.
  • #6: So before you've started writing any code your package.json is going to look something like this!
  • #8: Let's backup for a second. What you *really* care about is actually a small number of packages. These are actually *really* simple to learn. You’ll spend 4 hours learning this, and two weeks getting the tooling to work.
  • #9: By the end, you’ll feel like this. So what I'm really saying is, copy someone else's boilerplate example.
  • #10: Let’s try to remember what we’re trying to achieve
  • #11: You might have seen this before. https://facebook.github.io/flux/docs/overview.html
  • #12: Gross oversimplification of redux. Or is it? The view executes actions via the dispatcher. Actions update the store (state) via reducers. The store updates the view via connect() to react props.
  • #14: This is what you see… Too simple. How do I make a server request?? Source: https://github.com/reactjs/redux/blob/master/examples/todomvc/actions/index.js
  • #15: The key is always return a new object when you manipulate the store. It lets redux optimize react render passes. Source: https://github.com/reactjs/redux/blob/master/examples/todomvc/reducers/todos.js
  • #16: Ok so that's what you (probably) already knew about redux.
  • #17: If you’re use Python’s record type or Ruby’s struct… it’s just like that. Easy peasy data classes. Immutability is pretty much essential for redux because of how it optimizes updates. Immutable.js is definitely cleaner than using Object.assign and spread/ rest to create new objects. (It’s also faster.)
  • #18: If you’re use Python’s record type or Ruby’s struct… it’s just like that. Easy peasy data classes. Immutability is pretty much essential for redux because of how it optimizes updates. Immutable.js is definitely cleaner than using Object.assign and spread/ rest to create new objects. (It’s also faster.)
  • #19: Should stores hold a single object? A list if it’s
  • #20: I’ve got a list of nested items on the left… So immediately I know I need stores to hold a sequence of items. But also I need to be able to determine relations between items. (Normalizr helps with this.) In addition to the same item appearing both in the list and the main section. Long term you might want something like an LRU to deal with paging and data bloat.
  • #21: I need to be able to determine relations between items. (Normalizr helps with this.) I decided stores should be maps of my domain models. They have child/parent ID references so you can lookup corresponding parent children in each store. Long term you might want something like an LRU to deal with paging and data bloat.
  • #22: The reason why actions are disconnected from reducers is because they are not always 1-to-1. On line 35 the transmitter (child) reducer is populating the store from children in a fetched parent object.
  • #23: Let's look at connecting your store to view components. The connect method of react-redux is awesome. • Components are completely unaware of redux. • Connect() wrapped components have stores (state) and actions injected into props. • This makes un-connected components easily testable. • If you've done Java/Spring this feels like dependency injection
  • #24: This is why you need redux-thunk. Basically to do anything async. IDK why it’s not part of redux or react-redux. When you execute your action, return the promise and you can do things like navigation, close a dialog, etc. when the action completes.
  • #25: On line 81 I’m calling an action then closing a dialog and navigating to a new page (line 83) when successful. I could also perform specific steps if the action failed (e.g. 409 conflict on the server) If you ask me this is more appropriate place to put this logic than e.g. by getting a result from a store.
  • #26: Components wrapped in connect() can’t be searched for by Component name in shallow render tests. :( Erik Ras proposes exposing both a connected and non-connected component. See: https://github.com/erikras/ducks-modular-redux But testing stores is trivial!!!
  • #27: The connect() method has a workaround: see the `withRef` option. https://github.com/reactjs/react-redux/blob/master/docs/api.md This is actually a perfect example of how react state “traps” the application state.
  • #28: Instead of calling a method to get or change a component’s state, consider passing it from child to parent via a callback, and/or changing by dispatching a redux action. • Benefit: any part of the view heirarchy can now manipulate that state. E.g. a root view closing all dialogs. • Line 23 is calling a redux action. • Line 29 is an example of calling `closeDialogAction` in a promise chain
  • #29: The connect() method has a workaround: see the `withRef` option. https://github.com/reactjs/react-redux/blob/master/docs/api.md
  • #30: Should stores hold a single object? A list if it’s
  • #31: Actions that might be required by multiple disconnected components (e.g. initial data on page load) can easily be debounced to multiple expensive requests.
  • #32: This is how I manage the loading state. actionStarted() dispatches a loading increment action dispatchActionComplete() and dispatchError() does a decrement.
  • #33: Redux form solves the problem of trapping current form value in state
  • #34: Code for validation is trivial
  • #35: Andrew did a great presentation last month about React.js and I don’t think he used any flux framework. It works! • The unidirectional data flow does great things by itself. • You can build the rest (remote calls + app state) without too much effort.
  • #36: I’m thinking about ordering some shirts on Teespring – who’s interested? :D The end.
  • #37: I work at VoltServer – we make some pretty cool power disitribution technology. Ask me about Digital Electricity. It’s pretty rad.
  • #38: Extra stuff if there are questions.
  • #39: Actions are simple… Really simple.
  • #40: Replaced standard fetch actions with thunks to create cookie-cutter actions.
  • #41: Actions that might be required by multiple disconnected components (e.g. initial data on page load) can easily be debounced to multiple expensive requests.