SlideShare uma empresa Scribd logo
1 de 32
Baixar para ler offline
Enhance your User (and Developer)
Experience with React & Redux
& /phacks
Hi! I am Nicolas Goutay. I work at Theodo, a web
consultancy based in Paris & London. I build JS &
Python web applications. I like music, typography
and I have stage fright am excited to be here with all
of you. You can find me online (Twitter & GitHub) on
@phacks.
React & Redux
A Lego analogy
React would be a Lego instruction manual, where
bricks are DOM nodes. It takes care of how things
look for the end user.
test te
fort veau
jean jean
humain loup
travers des
gout bon
bonbon
cher non
How to build a F1
On modern Web apps, how things look are usually a
function of user interactions. In this analogy, the
user is Elya, my 5 year-old niece. Red is her favorite
color, so she wants the car to be red 🏎.
This is where 🤖 Redux kicks in.
# “I want the car to be red.”
🤖 “Dispatch the CHANGE_CAR_COLOR action with the
payload color: red”
$ “OK! I take note that you want your car red…”
🤖 “A reducer will process the action, and will add
color: red to the Redux store”
$ “…I sift through all the messy Legos to find red bricks…”
🤖 “The store passes the property color: red to
React components”
$ “…and I follow the instructions again with the red bricks”
test te
fort veau
jean jean
humain loup
travers des
gout bon
bonbon
cher non
How to build a F1
Redux store
color: red
# “I want the car number to by my age, not yours”
🤖 “Dispatch the CHANGE_CAR_NUMBER action with the
payload number: 5”
$ “Oh there we go again. 5 it is…”
🤖 “A reducer will process the action, and will add
number: 5 to the Redux store”
$ “…Where on Earth did I put this sticker…”
🤖 “The store passes the property number: 5 to
React components”
$ “…there you go! Now go find your parents 😅”
test te
fort veau
jean jean
humain loup
travers des
gout bon
bonbon
cher non
How to build a F1
Redux store
color: red
number: 5
Redux — Now with actual code
export function changeCarColor(color) {
return {
type: 'CHANGE_CAR_COLOR',
color
}
}
🤖 “Dispatch the CHANGE_CAR_COLOR action with the
payload color”
Redux — Now with actual code
function formulaOneApp(state = {}, action) {
switch (action.type) {
case 'CHANGE_CAR_COLOR':
return Object.assign({}, state, {
color: action.color
})
default:
return state
}
}
🤖 “A reducer will process the action, and will add
color to the Redux store”
Redux — Now with actual code
🤖 “The store passes the properties color and
number to React components”
import React from 'react'
const FormulaOne = ({ color, number }) => (
<div>
<CarBody color={color} />
<Decorations number={number} />
</div>
)
Developer Experience — Easier Debugging
Developer Experience — Easier Debugging
Developer Experience — Easier Debugging
This is what the Redux Store of my current project
look like. I can inspect every variable, which are
updated in real time.
User Experience — Built-in Performance
User Experience — Built-in Performance
React components are only repainted when their
props or inner state change.
React API methods like shouldComponentUpdate
allow us to have a finer-grained control about render
performance.
Developer Experience — “Reasonaboutability”
Developer Experience — “Reasonaboutability”
React developer Jani Eväkallio coined the term
“reasonaboutability” (easiness to reason about). I
love it, and it matches perfectly what I feel about
Redux. Here are the Three Principles of Redux:
Developer Experience — “Reasonaboutability”
React developer Jani Eväkallio coined the term
“reasonaboutability” (easiness to reason about). I
love it, and it matches perfectly what I feel about
Redux. Here are the Three Principles of Redux:
Single Source of Truth: all the data/UI state displayed on the
app come from the same JS object. Facilitates debugging.
Developer Experience — “Reasonaboutability”
React developer Jani Eväkallio coined the term
“reasonaboutability” (easiness to reason about). I
love it, and it matches perfectly what I feel about
Redux. Here are the Three Principles of Redux:
Single Source of Truth: all the data/UI state displayed on the
app come from the same JS object. Facilitates debugging.
State is read-only: The only way to change the state is to
emit an action, an object describing what happened.
Provides a single, robust & semantic way to deal with
interactions.
Developer Experience — “Reasonaboutability”
React developer Jani Eväkallio coined the term
“reasonaboutability” (easiness to reason about). I
love it, and it matches perfectly what I feel about
Redux. Here are the Three Principles of Redux:
Single Source of Truth: all the data/UI state displayed on the
app come from the same JS object. Facilitates debugging.
State is read-only: The only way to change the state is to
emit an action, an object describing what happened.
Provides a single, robust & semantic way to deal with
interactions.
Changes are made with pure functions: the Store can only
be updated with pure functions (reducers). Prevents nasty
side effects.
Redux comes with other benefits — and tradeoffs
🤩 Tests are blissfully easy to write: Reducers are pure
functions. Just test that given an input, they yield the right
output.
it('handles ADD_ITEM by adding the item', () => {
const initialState = fromJS({
todos: [
{id: 1, text: 'React', status: 'active'}
]
});
const action = {
type: 'ADD_ITEM',
text: 'Redux'
}
const nextState = reducer(initialState, action);
expect(nextState).to.equal(fromJS({
todos: [
{id: 1, text: 'React', status: 'active'},
{id: 2, text: 'Redux', status: 'active'},
]
}));
});
🛠 Rich ecosystem: Redux has an API to plug-in middlewares.
There are tons of them: for logging, offline capabilities,
async, forms, optimistic UIs…
Tip: 🔗 github.com/markerikson/react-redux-links is a
great place to start!
🤓 Code structure is key: Since all UI is derived from a single
JS object, it needs to be carefully designed and constantly
adjusted to business requirements.
Tip: Learn from the best! Twitter & Pinterest both use Redux,
and the structure is available for anybody to see with the
React Dev Tools!
Tip: I just got used to it. After a while it even feels more productive
than Angular 1, because you know exactly what to do to get
everything to work together.
😓 Verbosity: to write a feature, you would usually need to
write an action, a reducer, a selector, a saga… It feels quite
cumbersome compared to Angular 1.
Conclusion
React with Redux is a mature framework that
empowers developers to produce better apps in a
much better way.
Want to dive in?
I wrote a full-featured, test-driven tutorial on writing
a Todo List using React & Redux
🔗 http://github.com/phacks/redux-todomvc
Danke!
Slides are available at phacks.github.io
& /phacks

Mais conteúdo relacionado

Semelhante a #FrontConf2017 — Enhance your User (and Developer) Experience with React & Redux

Connecting with the enterprise - The how and why of connecting to Enterprise ...
Connecting with the enterprise - The how and why of connecting to Enterprise ...Connecting with the enterprise - The how and why of connecting to Enterprise ...
Connecting with the enterprise - The how and why of connecting to Enterprise ...Kevin Poorman
 
Rethinking Best Practices
Rethinking Best PracticesRethinking Best Practices
Rethinking Best Practicesfloydophone
 
All a flutter about Flutter.io
All a flutter about Flutter.ioAll a flutter about Flutter.io
All a flutter about Flutter.ioSteven Cooper
 
Mobile App Feature Configuration and A/B Experiments
Mobile App Feature Configuration and A/B ExperimentsMobile App Feature Configuration and A/B Experiments
Mobile App Feature Configuration and A/B Experimentslacyrhoades
 
High Performance web apps in Om, React and ClojureScript
High Performance web apps in Om, React and ClojureScriptHigh Performance web apps in Om, React and ClojureScript
High Performance web apps in Om, React and ClojureScriptLeonardo Borges
 
Intro to BackboneJS + Intermediate Javascript
Intro to BackboneJS + Intermediate JavascriptIntro to BackboneJS + Intermediate Javascript
Intro to BackboneJS + Intermediate JavascriptAndrew Lovett-Barron
 
React js - The Core Concepts
React js - The Core ConceptsReact js - The Core Concepts
React js - The Core ConceptsDivyang Bhambhani
 
Rubyconf2016 - Solving communication problems in distributed teams with BDD
Rubyconf2016 - Solving communication problems in distributed teams with BDDRubyconf2016 - Solving communication problems in distributed teams with BDD
Rubyconf2016 - Solving communication problems in distributed teams with BDDRodrigo Urubatan
 
The State of Front-end At CrowdTwist
The State of Front-end At CrowdTwistThe State of Front-end At CrowdTwist
The State of Front-end At CrowdTwistMark Fayngersh
 
React && React Native workshop
React && React Native workshopReact && React Native workshop
React && React Native workshopStacy Goh
 
Plugin for Plugin, или расширяем Android New Build System. Антон Руткевич
 Plugin for Plugin, или расширяем Android New Build System. Антон Руткевич Plugin for Plugin, или расширяем Android New Build System. Антон Руткевич
Plugin for Plugin, или расширяем Android New Build System. Антон РуткевичYandex
 
Connect.js - Exploring React.Native
Connect.js - Exploring React.NativeConnect.js - Exploring React.Native
Connect.js - Exploring React.Nativejoshcjensen
 
N Things You Don't Want to Repeat in React Native
N Things You Don't Want to Repeat in React NativeN Things You Don't Want to Repeat in React Native
N Things You Don't Want to Repeat in React NativeAnton Kulyk
 
Let's discover React and Redux with TypeScript
Let's discover React and Redux with TypeScriptLet's discover React and Redux with TypeScript
Let's discover React and Redux with TypeScriptMathieu Savy
 
Professional JavaScript: AntiPatterns
Professional JavaScript: AntiPatternsProfessional JavaScript: AntiPatterns
Professional JavaScript: AntiPatternsMike Wilcox
 
resolvendo problemas de comunicação em equipes distribuídas com bdd
resolvendo problemas de comunicação em equipes distribuídas com bddresolvendo problemas de comunicação em equipes distribuídas com bdd
resolvendo problemas de comunicação em equipes distribuídas com bddRodrigo Urubatan
 
Intro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScriptIntro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScriptjasonsich
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsJeff Durta
 

Semelhante a #FrontConf2017 — Enhance your User (and Developer) Experience with React & Redux (20)

Connecting with the enterprise - The how and why of connecting to Enterprise ...
Connecting with the enterprise - The how and why of connecting to Enterprise ...Connecting with the enterprise - The how and why of connecting to Enterprise ...
Connecting with the enterprise - The how and why of connecting to Enterprise ...
 
Rethinking Best Practices
Rethinking Best PracticesRethinking Best Practices
Rethinking Best Practices
 
All a flutter about Flutter.io
All a flutter about Flutter.ioAll a flutter about Flutter.io
All a flutter about Flutter.io
 
Mobile App Feature Configuration and A/B Experiments
Mobile App Feature Configuration and A/B ExperimentsMobile App Feature Configuration and A/B Experiments
Mobile App Feature Configuration and A/B Experiments
 
Huge web apps web expo 2013
Huge web apps web expo 2013Huge web apps web expo 2013
Huge web apps web expo 2013
 
High Performance web apps in Om, React and ClojureScript
High Performance web apps in Om, React and ClojureScriptHigh Performance web apps in Om, React and ClojureScript
High Performance web apps in Om, React and ClojureScript
 
Simple React Todo List
Simple React Todo ListSimple React Todo List
Simple React Todo List
 
Intro to BackboneJS + Intermediate Javascript
Intro to BackboneJS + Intermediate JavascriptIntro to BackboneJS + Intermediate Javascript
Intro to BackboneJS + Intermediate Javascript
 
React js - The Core Concepts
React js - The Core ConceptsReact js - The Core Concepts
React js - The Core Concepts
 
Rubyconf2016 - Solving communication problems in distributed teams with BDD
Rubyconf2016 - Solving communication problems in distributed teams with BDDRubyconf2016 - Solving communication problems in distributed teams with BDD
Rubyconf2016 - Solving communication problems in distributed teams with BDD
 
The State of Front-end At CrowdTwist
The State of Front-end At CrowdTwistThe State of Front-end At CrowdTwist
The State of Front-end At CrowdTwist
 
React && React Native workshop
React && React Native workshopReact && React Native workshop
React && React Native workshop
 
Plugin for Plugin, или расширяем Android New Build System. Антон Руткевич
 Plugin for Plugin, или расширяем Android New Build System. Антон Руткевич Plugin for Plugin, или расширяем Android New Build System. Антон Руткевич
Plugin for Plugin, или расширяем Android New Build System. Антон Руткевич
 
Connect.js - Exploring React.Native
Connect.js - Exploring React.NativeConnect.js - Exploring React.Native
Connect.js - Exploring React.Native
 
N Things You Don't Want to Repeat in React Native
N Things You Don't Want to Repeat in React NativeN Things You Don't Want to Repeat in React Native
N Things You Don't Want to Repeat in React Native
 
Let's discover React and Redux with TypeScript
Let's discover React and Redux with TypeScriptLet's discover React and Redux with TypeScript
Let's discover React and Redux with TypeScript
 
Professional JavaScript: AntiPatterns
Professional JavaScript: AntiPatternsProfessional JavaScript: AntiPatterns
Professional JavaScript: AntiPatterns
 
resolvendo problemas de comunicação em equipes distribuídas com bdd
resolvendo problemas de comunicação em equipes distribuídas com bddresolvendo problemas de comunicação em equipes distribuídas com bdd
resolvendo problemas de comunicação em equipes distribuídas com bdd
 
Intro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScriptIntro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScript
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
 

Último

Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 

Último (20)

Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 

#FrontConf2017 — Enhance your User (and Developer) Experience with React & Redux

  • 1. Enhance your User (and Developer) Experience with React & Redux & /phacks
  • 2. Hi! I am Nicolas Goutay. I work at Theodo, a web consultancy based in Paris & London. I build JS & Python web applications. I like music, typography and I have stage fright am excited to be here with all of you. You can find me online (Twitter & GitHub) on @phacks.
  • 3. React & Redux A Lego analogy
  • 4. React would be a Lego instruction manual, where bricks are DOM nodes. It takes care of how things look for the end user.
  • 5. test te fort veau jean jean humain loup travers des gout bon bonbon cher non How to build a F1
  • 6. On modern Web apps, how things look are usually a function of user interactions. In this analogy, the user is Elya, my 5 year-old niece. Red is her favorite color, so she wants the car to be red 🏎.
  • 7. This is where 🤖 Redux kicks in.
  • 8. # “I want the car to be red.” 🤖 “Dispatch the CHANGE_CAR_COLOR action with the payload color: red” $ “OK! I take note that you want your car red…” 🤖 “A reducer will process the action, and will add color: red to the Redux store” $ “…I sift through all the messy Legos to find red bricks…” 🤖 “The store passes the property color: red to React components” $ “…and I follow the instructions again with the red bricks”
  • 9. test te fort veau jean jean humain loup travers des gout bon bonbon cher non How to build a F1 Redux store color: red
  • 10. # “I want the car number to by my age, not yours” 🤖 “Dispatch the CHANGE_CAR_NUMBER action with the payload number: 5” $ “Oh there we go again. 5 it is…” 🤖 “A reducer will process the action, and will add number: 5 to the Redux store” $ “…Where on Earth did I put this sticker…” 🤖 “The store passes the property number: 5 to React components” $ “…there you go! Now go find your parents 😅”
  • 11. test te fort veau jean jean humain loup travers des gout bon bonbon cher non How to build a F1 Redux store color: red number: 5
  • 12. Redux — Now with actual code export function changeCarColor(color) { return { type: 'CHANGE_CAR_COLOR', color } } 🤖 “Dispatch the CHANGE_CAR_COLOR action with the payload color”
  • 13. Redux — Now with actual code function formulaOneApp(state = {}, action) { switch (action.type) { case 'CHANGE_CAR_COLOR': return Object.assign({}, state, { color: action.color }) default: return state } } 🤖 “A reducer will process the action, and will add color to the Redux store”
  • 14. Redux — Now with actual code 🤖 “The store passes the properties color and number to React components” import React from 'react' const FormulaOne = ({ color, number }) => ( <div> <CarBody color={color} /> <Decorations number={number} /> </div> )
  • 15. Developer Experience — Easier Debugging
  • 16. Developer Experience — Easier Debugging
  • 17. Developer Experience — Easier Debugging This is what the Redux Store of my current project look like. I can inspect every variable, which are updated in real time.
  • 18. User Experience — Built-in Performance
  • 19. User Experience — Built-in Performance React components are only repainted when their props or inner state change. React API methods like shouldComponentUpdate allow us to have a finer-grained control about render performance.
  • 20. Developer Experience — “Reasonaboutability”
  • 21. Developer Experience — “Reasonaboutability” React developer Jani Eväkallio coined the term “reasonaboutability” (easiness to reason about). I love it, and it matches perfectly what I feel about Redux. Here are the Three Principles of Redux:
  • 22. Developer Experience — “Reasonaboutability” React developer Jani Eväkallio coined the term “reasonaboutability” (easiness to reason about). I love it, and it matches perfectly what I feel about Redux. Here are the Three Principles of Redux: Single Source of Truth: all the data/UI state displayed on the app come from the same JS object. Facilitates debugging.
  • 23. Developer Experience — “Reasonaboutability” React developer Jani Eväkallio coined the term “reasonaboutability” (easiness to reason about). I love it, and it matches perfectly what I feel about Redux. Here are the Three Principles of Redux: Single Source of Truth: all the data/UI state displayed on the app come from the same JS object. Facilitates debugging. State is read-only: The only way to change the state is to emit an action, an object describing what happened. Provides a single, robust & semantic way to deal with interactions.
  • 24. Developer Experience — “Reasonaboutability” React developer Jani Eväkallio coined the term “reasonaboutability” (easiness to reason about). I love it, and it matches perfectly what I feel about Redux. Here are the Three Principles of Redux: Single Source of Truth: all the data/UI state displayed on the app come from the same JS object. Facilitates debugging. State is read-only: The only way to change the state is to emit an action, an object describing what happened. Provides a single, robust & semantic way to deal with interactions. Changes are made with pure functions: the Store can only be updated with pure functions (reducers). Prevents nasty side effects.
  • 25. Redux comes with other benefits — and tradeoffs
  • 26. 🤩 Tests are blissfully easy to write: Reducers are pure functions. Just test that given an input, they yield the right output. it('handles ADD_ITEM by adding the item', () => { const initialState = fromJS({ todos: [ {id: 1, text: 'React', status: 'active'} ] }); const action = { type: 'ADD_ITEM', text: 'Redux' } const nextState = reducer(initialState, action); expect(nextState).to.equal(fromJS({ todos: [ {id: 1, text: 'React', status: 'active'}, {id: 2, text: 'Redux', status: 'active'}, ] })); });
  • 27. 🛠 Rich ecosystem: Redux has an API to plug-in middlewares. There are tons of them: for logging, offline capabilities, async, forms, optimistic UIs… Tip: 🔗 github.com/markerikson/react-redux-links is a great place to start!
  • 28. 🤓 Code structure is key: Since all UI is derived from a single JS object, it needs to be carefully designed and constantly adjusted to business requirements. Tip: Learn from the best! Twitter & Pinterest both use Redux, and the structure is available for anybody to see with the React Dev Tools!
  • 29. Tip: I just got used to it. After a while it even feels more productive than Angular 1, because you know exactly what to do to get everything to work together. 😓 Verbosity: to write a feature, you would usually need to write an action, a reducer, a selector, a saga… It feels quite cumbersome compared to Angular 1.
  • 30. Conclusion React with Redux is a mature framework that empowers developers to produce better apps in a much better way.
  • 31. Want to dive in? I wrote a full-featured, test-driven tutorial on writing a Todo List using React & Redux 🔗 http://github.com/phacks/redux-todomvc
  • 32. Danke! Slides are available at phacks.github.io & /phacks