Making react part of something greater

Darko Kukovec
Darko KukovecJavaScript Developer at Infinum
Making React part of
something greater
DARKO KUKOVEC
JS TEAM LEAD @ INFINUM
@DarkoKukovec
WHAT AM I TALKING ABOUT?
• React
WHAT AM I TALKING ABOUT?
• React
• React state management libs
• Comparison of two libs
WHAT AM I TALKING ABOUT?
• React
• React state management libs
• Comparison of two libs
• Biased?
01REACT
REACT
• Facebook
• Not a framework
REACT - THE WEIRD PARTS
• JSX?!?
• Different way of thinking
• Component state
REACT - THE GOOD PARTS
• Virtual DOM
• Think about the end goal, not about the journey
• You render the final state
• React takes care of the actual changes
• Efficient
REACT
• Component = View + UI State + Event handling
Source: https://medium.freecodecamp.com/is-mvc-dead-for-the-frontend-35b4d1fe39ec
02STATE MANAGEMENT
STATE MANAGEMENT
• React - Encapsulated UI Components
• Application State & Business logic?
STATE MANAGEMENT
Source: https://medium.freecodecamp.com/is-mvc-dead-for-the-frontend-35b4d1fe39ec
DIY STATE MANAGEMENT
• OK for basic use cases?
• Model objects
• Services
DIY STATE MANAGEMENT
• How to (efficiently) rerender component on data change?
• setState is tricky
DIY STATE MANAGEMENT
• How to (efficiently) rerender component on data change?
• setState is tricky
• Standards…
Source: https://xkcd.com/927/
MRC - MODEL-REACT-CONTROLLER
• e.g. Replace Backbone views with components
• http://todomvc.com/examples/react-backbone/
• Backbone mutable by nature -> Bad for React perf
• Legacy codebase?
FLUX
FLUX
• Facebook, 2014
• Unidirectional architecture
• Data down, actions up
FLUX
• Data down, actions up
Source: http://fluxxor.com/what-is-flux.html
FLUX
• Data down, actions up
Source: http://fluxxor.com/what-is-flux.html
FLUX
• Store
• Business logic + Application state
• Only one allowed to change application state
• All actions synchronous
• Async operations trigger actions on state change
REDUX
REDUX
• Single store (with nesting)
• Application state
• UI State
• Reducers
• Business logic
• Responsible for one part of the store
• Immutable state
REDUX
Source: https://www.theodo.fr/blog/2016/03/getting-started-with-react-redux-and-immutable-a-test-driven-tutorial-part-2/
REDUX
• Time travel
REDUX
• Time travel
REDUX
• Time travel
• Redux Dev Tools
Source: https://github.com/gaearon/redux-devtools-dock-monitor
REDUX
• A lot of boilerplate code
• Async actions very verbose
MOBX
MOBX
Actions
Observable
Observers
Computed
values
Our state
Our components
MOBX - UPDATES
• Observers & computed values notified only on relevant changes
• Topic for another talk
MOBX
• Faster than Redux
• Redux - component render on (sub)store update
• MobX - component render on specific property update
MOBX VS. REDUX PERFORMANCE
Source: https://twitter.com/mweststrate/status/718444275239882753
MOBX VS. REDUX PERFORMANCE
Source: https://twitter.com/mweststrate/status/718444275239882753
Time in ms
MOBX
• Decorators
• @observable
• @calculated
• @action
• etc.
• TypeScript or Babel
• Not a requirement!
MORE ALTERNATIVES
RELAY
• Facebook
• GraphQL - API query language
RXJS
• not intended for this
• can mimic Redux
• “Observable states”
03REDUX VS. MOBX
REDUX VS. MOBX
Redux
Faster
Flexible
MobX
Bigger community
Better Dev Tools
REDUX VS. MOBX
Redux
Faster
Less boilerplate
Flexible
MobX
Bigger community
Better Dev Tools
Less magic
Source: https://twitter.com/phillip_webb/status/705909774001377280
EXAMPLE TIME!
Conference app
Load & choose talks
Setup
// ApplicationStore.js
const defaultState = {list: [], loading: false};
export default function(state = defaultState, action) {
switch(action.type) {
default:
return state;
}
}
Redux
Initial reducer setup
// TalkStore.js
import {observable} from "mobx";
export const talks = observable({
list: [],
loading: false
});
MobX
Initial observable setup
Load data
// MyComponent.js
dispatch(loadTalksAction());
// TalkActions.js
async function loadTalksAction() {
dispatch({name: TALK_LIST_LOAD});
const talks = await loadTalks();
dispatch({name: TALK_LIST_LOADED, talks});
}
// TalkReducer.js
case TALK_LIST_LOAD:
return {...state, list: [], loading: true};
case TALK_LIST_LOADED:
return {...state, list: action.talks, loading: true};
Redux
Load a list of items (redux-thunk)
// MyComponent.js
loadTalksAction();
// TalkActions.js
async function loadTalksAction() {
talks.loading = true;
talks.list = await loadTalks();
talks.loading = false;
}
MobX
Load a list of items
Modify data
// MyComponent.js
dispatch(selectTalkAction(this.props.talk));
// TalkActions.js
function selectTalkAction(talk) {
return {name: TALK_SELECT, talk.id};
}
// TalkReducer.js
case TALK_SELECT:
return {
...state,
list: state.list.map((item) => {
if (item.id === action.talk.id)
return {...item, selected: true};
else return item;
}),
loading: false
};
Redux
Choose a talk
// MyComponent.js
selectTalkAction(this.props.talk);
// TalkActions.js
function selectTalkAction(talk) {
talk.selected = true;
}
// TalkStore.js
import {computed} from ’mobx’;
export const talks = observable({
list: [],
loading: false,
@computed get selected() {
return this.list.filter((item) => item.selected);
}
});
MobX
Choose a talk
MobX useStrict
import {useStrict} from "mobx";
useStrict(true);
// In a random place
function selectTalkAction(talk) {
talk.selected = true;
}
// [mobx] Invariant failed: It is not allowed to create or
change state outside an `action` when MobX is in strict
mode. Wrap the current method in `action` if this state
change is intended
// TalkActions.js
@action function selectTalkAction(talk) {
talk.selected = true;
}
MobX
useStrict
04ENOUGH ABOUT MOBX,
LET’S TALK ABOUT MOBX
MOBX DEVTOOLS
• 3 options
• Redraws
MOBX DEVTOOLS
• 3 options
• Redraws
• Dependencies
MOBX DEVTOOLS
• 3 options
• Redraws
• Dependencies
• Actions/reactions
RELATED PROJECTS
• React bindings
• React Native bindings
• Meteor bindings
• Firebase
• Routers, models, forms, loggers, etc.
<3 OPEN SOURCE
• https://github.com/infinum
• react-mobx-translatable
• mobx-keys-store
• mobx-jsonapi-store
• mobx-form-store (soon)
RESOURCES
• http://mobxjs.github.io/mobx/
• https://mobxjs.github.io/mobx/getting-started.html
• https://medium.com/@mweststrate/object-observe-is-dead-long-
live-mobservable-observe-ad96930140c5
• https://medium.com/@mweststrate/3-reasons-why-i-stopped-
using-react-setstate-ab73fc67a42e
SHOULD YOU USE MOBX?
IT DEPENDSTM
Thank you!
DARKO@INFINUM.CO
@DARKOKUKOVEC
Visit infinum.co or find us on social networks:
infinum.co infinumco infinumco infinum
JOIND.IN
joind.in/talk/bdddf
darko.im
Any questions?
DARKO@INFINUM.CO
@DARKOKUKOVEC
Visit infinum.co or find us on social networks:
infinum.co infinumco infinumco infinum
JOIND.IN
joind.in/talk/bdddf
darko.im
1 of 63

Recommended

React state management with Redux and MobX by
React state management with Redux and MobXReact state management with Redux and MobX
React state management with Redux and MobXDarko Kukovec
2K views93 slides
Mobx for Dummies - Yauheni Nikanowich - React Warsaw #5 by
Mobx for Dummies - Yauheni Nikanowich - React Warsaw #5Mobx for Dummies - Yauheni Nikanowich - React Warsaw #5
Mobx for Dummies - Yauheni Nikanowich - React Warsaw #5Marcin Mieszek
1.1K views22 slides
Using redux by
Using reduxUsing redux
Using reduxJonas Ohlsson Aden
3.4K views22 slides
Designing applications with Redux by
Designing applications with ReduxDesigning applications with Redux
Designing applications with ReduxFernando Daciuk
1.2K views82 slides
Redux js by
Redux jsRedux js
Redux jsNils Petersohn
3.5K views21 slides
State Models for React with Redux by
State Models for React with ReduxState Models for React with Redux
State Models for React with ReduxStephan Schmidt
3.9K views47 slides

More Related Content

What's hot

Redux data flow with angular 2 by
Redux data flow with angular 2Redux data flow with angular 2
Redux data flow with angular 2Gil Fink
1.8K views31 slides
Angular redux by
Angular reduxAngular redux
Angular reduxNir Kaufman
5.6K views49 slides
The Road To Redux by
The Road To ReduxThe Road To Redux
The Road To ReduxJeffrey Sanchez
2.6K views41 slides
Better React state management with Redux by
Better React state management with ReduxBetter React state management with Redux
Better React state management with ReduxMaurice De Beijer [MVP]
632 views78 slides
How to Redux by
How to ReduxHow to Redux
How to ReduxTed Pennings
1.9K views18 slides
Getting started with Redux js by
Getting started with Redux jsGetting started with Redux js
Getting started with Redux jsCitrix
482 views23 slides

What's hot(20)

Redux data flow with angular 2 by Gil Fink
Redux data flow with angular 2Redux data flow with angular 2
Redux data flow with angular 2
Gil Fink1.8K views
Angular redux by Nir Kaufman
Angular reduxAngular redux
Angular redux
Nir Kaufman5.6K views
Getting started with Redux js by Citrix
Getting started with Redux jsGetting started with Redux js
Getting started with Redux js
Citrix482 views
Reactive Streams and RxJava2 by Yakov Fain
Reactive Streams and RxJava2Reactive Streams and RxJava2
Reactive Streams and RxJava2
Yakov Fain3.9K views
Event sourcing with reactor and spring statemachine by Jimmy Lu
Event sourcing with reactor and spring statemachineEvent sourcing with reactor and spring statemachine
Event sourcing with reactor and spring statemachine
Jimmy Lu5.5K views
Building React Applications with Redux by FITC
Building React Applications with ReduxBuilding React Applications with Redux
Building React Applications with Redux
FITC2.1K views
React + Redux + TypeScript === ♥ by Remo Jansen
React + Redux + TypeScript === ♥React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥
Remo Jansen12.6K views
Creating a WYSIWYG Editor with React by peychevi
Creating a WYSIWYG Editor with ReactCreating a WYSIWYG Editor with React
Creating a WYSIWYG Editor with React
peychevi13.3K views
Modern Web Developement by peychevi
Modern Web DevelopementModern Web Developement
Modern Web Developement
peychevi5.2K views
ProvJS: Six Months of ReactJS and Redux by Thom Nichols
ProvJS:  Six Months of ReactJS and ReduxProvJS:  Six Months of ReactJS and Redux
ProvJS: Six Months of ReactJS and Redux
Thom Nichols836 views
An Overview of the React Ecosystem by FITC
An Overview of the React EcosystemAn Overview of the React Ecosystem
An Overview of the React Ecosystem
FITC1.7K views
JS Chicago Meetup 2/23/16 - Redux & Routes by Nick Dreckshage
JS Chicago Meetup 2/23/16 - Redux & RoutesJS Chicago Meetup 2/23/16 - Redux & Routes
JS Chicago Meetup 2/23/16 - Redux & Routes
Nick Dreckshage600 views
Academy PRO: React JS. Redux & Tooling by Binary Studio
Academy PRO: React JS. Redux & ToolingAcademy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & Tooling
Binary Studio425 views

Similar to Making react part of something greater

Advanced React by
Advanced ReactAdvanced React
Advanced ReactMike Wilcox
360 views22 slides
A React Journey by
A React JourneyA React Journey
A React JourneyLinkMe Srl
925 views44 slides
Spfx with react redux by
Spfx with react reduxSpfx with react redux
Spfx with react reduxRajesh Kumar
1K views23 slides
React gsg presentation with ryan jung &amp; elias malik by
React   gsg presentation with ryan jung &amp; elias malikReact   gsg presentation with ryan jung &amp; elias malik
React gsg presentation with ryan jung &amp; elias malikLama K Banna
91 views32 slides
Redux data flow with angular by
Redux data flow with angularRedux data flow with angular
Redux data flow with angularGil Fink
352 views39 slides
Redux data flow with angular by
Redux data flow with angularRedux data flow with angular
Redux data flow with angularGil Fink
787 views39 slides

Similar to Making react part of something greater(20)

A React Journey by LinkMe Srl
A React JourneyA React Journey
A React Journey
LinkMe Srl925 views
React gsg presentation with ryan jung &amp; elias malik by Lama K Banna
React   gsg presentation with ryan jung &amp; elias malikReact   gsg presentation with ryan jung &amp; elias malik
React gsg presentation with ryan jung &amp; elias malik
Lama K Banna91 views
Redux data flow with angular by Gil Fink
Redux data flow with angularRedux data flow with angular
Redux data flow with angular
Gil Fink352 views
Redux data flow with angular by Gil Fink
Redux data flow with angularRedux data flow with angular
Redux data flow with angular
Gil Fink787 views
React js programming concept by Tariqul islam
React js programming conceptReact js programming concept
React js programming concept
Tariqul islam1.4K views
Introduction to React, Flux, and Isomorphic Apps by Federico Torre
Introduction to React, Flux, and Isomorphic AppsIntroduction to React, Flux, and Isomorphic Apps
Introduction to React, Flux, and Isomorphic Apps
Federico Torre989 views
Enhance react app with patterns - part 1: higher order component by Yao Nien Chung
Enhance react app with patterns - part 1: higher order componentEnhance react app with patterns - part 1: higher order component
Enhance react app with patterns - part 1: higher order component
Yao Nien Chung3.4K views
Corso su ReactJS by LinkMe Srl
Corso su ReactJSCorso su ReactJS
Corso su ReactJS
LinkMe Srl724 views
ReactJS - A quick introduction to Awesomeness by Ronny Haase
ReactJS - A quick introduction to AwesomenessReactJS - A quick introduction to Awesomeness
ReactJS - A quick introduction to Awesomeness
Ronny Haase334 views
Introduction to ReactJS and Redux by Boris Dinkevich
Introduction to ReactJS and ReduxIntroduction to ReactJS and Redux
Introduction to ReactJS and Redux
Boris Dinkevich474 views
Fundamental concepts of react js by StephieJohn
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react js
StephieJohn98 views
OttawaJS - React by rbl002
OttawaJS - ReactOttawaJS - React
OttawaJS - React
rbl002544 views
Content-Driven Apps with React by Netcetera
Content-Driven Apps with ReactContent-Driven Apps with React
Content-Driven Apps with React
Netcetera1.1K views

Recently uploaded

【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院 by
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院IttrainingIttraining
34 views8 slides
Data-centric AI and the convergence of data and model engineering: opportunit... by
Data-centric AI and the convergence of data and model engineering:opportunit...Data-centric AI and the convergence of data and model engineering:opportunit...
Data-centric AI and the convergence of data and model engineering: opportunit...Paolo Missier
34 views40 slides
AMAZON PRODUCT RESEARCH.pdf by
AMAZON PRODUCT RESEARCH.pdfAMAZON PRODUCT RESEARCH.pdf
AMAZON PRODUCT RESEARCH.pdfJerikkLaureta
15 views13 slides
Perth MeetUp November 2023 by
Perth MeetUp November 2023 Perth MeetUp November 2023
Perth MeetUp November 2023 Michael Price
15 views44 slides
From chaos to control: Managing migrations and Microsoft 365 with ShareGate! by
From chaos to control: Managing migrations and Microsoft 365 with ShareGate!From chaos to control: Managing migrations and Microsoft 365 with ShareGate!
From chaos to control: Managing migrations and Microsoft 365 with ShareGate!sammart93
9 views39 slides

Recently uploaded(20)

【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院 by IttrainingIttraining
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
Data-centric AI and the convergence of data and model engineering: opportunit... by Paolo Missier
Data-centric AI and the convergence of data and model engineering:opportunit...Data-centric AI and the convergence of data and model engineering:opportunit...
Data-centric AI and the convergence of data and model engineering: opportunit...
Paolo Missier34 views
AMAZON PRODUCT RESEARCH.pdf by JerikkLaureta
AMAZON PRODUCT RESEARCH.pdfAMAZON PRODUCT RESEARCH.pdf
AMAZON PRODUCT RESEARCH.pdf
JerikkLaureta15 views
Perth MeetUp November 2023 by Michael Price
Perth MeetUp November 2023 Perth MeetUp November 2023
Perth MeetUp November 2023
Michael Price15 views
From chaos to control: Managing migrations and Microsoft 365 with ShareGate! by sammart93
From chaos to control: Managing migrations and Microsoft 365 with ShareGate!From chaos to control: Managing migrations and Microsoft 365 with ShareGate!
From chaos to control: Managing migrations and Microsoft 365 with ShareGate!
sammart939 views
Voice Logger - Telephony Integration Solution at Aegis by Nirmal Sharma
Voice Logger - Telephony Integration Solution at AegisVoice Logger - Telephony Integration Solution at Aegis
Voice Logger - Telephony Integration Solution at Aegis
Nirmal Sharma17 views
HTTP headers that make your website go faster - devs.gent November 2023 by Thijs Feryn
HTTP headers that make your website go faster - devs.gent November 2023HTTP headers that make your website go faster - devs.gent November 2023
HTTP headers that make your website go faster - devs.gent November 2023
Thijs Feryn19 views
Case Study Copenhagen Energy and Business Central.pdf by Aitana
Case Study Copenhagen Energy and Business Central.pdfCase Study Copenhagen Energy and Business Central.pdf
Case Study Copenhagen Energy and Business Central.pdf
Aitana12 views
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors by sugiuralab
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors
sugiuralab15 views
Unit 1_Lecture 2_Physical Design of IoT.pdf by StephenTec
Unit 1_Lecture 2_Physical Design of IoT.pdfUnit 1_Lecture 2_Physical Design of IoT.pdf
Unit 1_Lecture 2_Physical Design of IoT.pdf
StephenTec11 views
Lilypad @ Labweek, Istanbul, 2023.pdf by Ally339821
Lilypad @ Labweek, Istanbul, 2023.pdfLilypad @ Labweek, Istanbul, 2023.pdf
Lilypad @ Labweek, Istanbul, 2023.pdf
Ally3398219 views
Five Things You SHOULD Know About Postman by Postman
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About Postman
Postman27 views
Piloting & Scaling Successfully With Microsoft Viva by Richard Harbridge
Piloting & Scaling Successfully With Microsoft VivaPiloting & Scaling Successfully With Microsoft Viva
Piloting & Scaling Successfully With Microsoft Viva
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N... by James Anderson
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
James Anderson33 views

Making react part of something greater