Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
JS Summit: Modular React & Redux
Search
Jeremy Fairbank
February 25, 2016
Programming
480
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
JS Summit: Modular React & Redux
Jeremy Fairbank
February 25, 2016
More Decks by Jeremy Fairbank
See All by Jeremy Fairbank
Connect.Tech 2020: Advanced Cypress Testing
jfairbank
1
260
CodeMash 2020: Solving the Boolean Identity Crisis
jfairbank
1
210
CodeMash 2020: Practical Functional Programming
jfairbank
1
360
Connect.Tech 2019: Practical Functional Programming
jfairbank
0
430
Connect.Tech 2019: Solving the Boolean Identity Crisis
jfairbank
0
240
Lambda Squared 2019: Solving the Boolean Identity Crisis
jfairbank
0
180
All Things Open 2018: Practical Functional Programming
jfairbank
2
280
Connect.Tech 2018: Effective React Testing
jfairbank
1
220
Fluent Conf 2018: Building web apps with Elm Tutorial
jfairbank
2
930
Other Decks in Programming
See All in Programming
「正の参照」と 「負の導出」で組む ハーネスエンジニアリング
cottpan
1
140
琵琶湖の水は止められてもNet--HTTPのリトライは止められない / You might be able to stop the water flow of Lake Biwa but you can't stop Net::HTTP retries
luccafort
PRO
0
270
Hatena Engineer Seminar #37「言語モデルの活用に関する研究」
slashnephy
0
520
関数型プログラミングのメリットって何だろう?
wanko_it
0
170
AI時代の仕事技芸論〜ソフトウェア開発で「遊ぶように働く」職人的熟達のすすめ(スクフェス仙台 2026バージョン)
kuranuki
0
620
AWS CDK を「作」ってみた 〜フルスクラッチで見えた CDK の裏側〜 / aws-cdk-from-scratch
gotok365
3
260
どこまでゆるくて許されるのか
tk3fftk
0
480
AI がコードを書く時代における新卒エンジニアの仕事風景 (2026) / New Graduate Engineers in the Era of AI Coding (2026)
sushichan044
0
220
OSINT for SRE: 学術論文とポストモーテムから探る システム障害の共通パターン / SRE NEXT 2026
tomoyk
1
3.6k
JAWS-UG横浜 #102 AWSサ終供養LT会 成仏できない AWS サービスたち 〜本日、三体供養します〜
maroon1st
0
140
【やさしく解説 設計編 #1】「ドメイン駆動」と「実装駆動」ってなに? 〜設計の考え方を、たとえ話で学ぼう〜
panda728
PRO
1
120
The Bowling Game- From Imperative to Functional Programming - Part 1
philipschwarz
PRO
0
320
Featured
See All Featured
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.1k
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
190
A designer walks into a library…
pauljervisheath
211
24k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
650
It's Worth the Effort
3n
188
29k
A better future with KSS
kneath
240
18k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
270
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
WCS-LA-2024
lcolladotor
0
690
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
62
44k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
220
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6k
Transcript
Jeremy Fairbank blog.jeremyfairbank.com @elpapapollo | github.com/jfairbank MODULAR React& redux
We help brands excel. pushagency.io Your website, SimplyBuilt. simplybuilt.com
https://commons.wikimedia.org/wiki/File:2001_Monolith.jpg
https://commons.wikimedia.org/wiki/File:Close_up_of_Hand_Cut_Jigsaw_Puzzle.JPG
Modularity • Independent • Single Responsibility • Small • Testable
• Apply to React components • Apply to Redux state and reducers
None
None
<Dashboard> <Panel label="Account"> <PanelItem>Name: {user.name}</PanelItem> <PanelItem>Username: {user.username}</PanelItem> <PanelItem>Email: {user.email}</PanelItem> </Panel>
</Dashboard>
class NameTag extends React.Component { componentWillMount() { this.setState({ name: this.props.name
}); } updateName(name) { this.setState({ name }); } render() { return ( <div> <p>Hello, my name is {this.state.name}</p> <p> <input type="text" value={this.state.name} onChange={e => this.updateName(e.target.value)} /> </p> </div> ); } } <NameTag name="Jeremy Fairbank"/>
<NameTag name="Jeremy Fairbank" onChange={myUpdateFunction}/> const NameTag = ({ name, onChange
}) => ( <div> <p> Hello, my name is {name} </p> <p> <input type="text" value={name} onChange={e => onChange(e.target.value)} /> </p> </div> );
PROBLEMS STATE AND RESPONSIBILITY
const NameTag = ({ name, onChange }) => ( <div>
<p> Hello, my name is {name} </p> <p> <input type="text" value={name} onChange={e => onChange(e.target.value)} /> </p> </div> ); External state
const NameTag = ({ name, onChange }) => ( <div>
<p> Hello, my name is {name} </p> <p> <input type="text" value={name} onChange={e => onChange(e.target.value)} /> </p> </div> ); Who manages the state?
class NameTag extends React.Component { componentWillMount() { this.setState({ name: this.props.name
}); } updateName(name) { this.setState({ name }); } render() { return ( <div> <p>Hello, my name is {this.state.name}</p> <p> <input type="text" value={this.state.name} onChange={e => this.updateName(e.target.value)} /> </p> </div> ); } }
class NameTag extends React.Component { componentWillMount() { this.setState({ name: this.props.name
}); } updateName(name) { this.setState({ name }); } render() { return ( <div> <p>Hello, my name is {this.state.name}</p> <p> <input type="text" value={this.state.name} onChange={e => this.updateName(e.target.value)} /> </p> </div> ); } }
class NameTag extends React.Component { componentWillMount() { this.setState({ name: this.props.name
}); } updateName(name) { this.setState({ name }); } render() { return ( <div> <p>Hello, my name is {this.state.name}</p> <p> <input type="text" value={this.state.name} onChange={e => this.updateName(e.target.value)} /> </p> </div> ); } } Many components => State strewn across app
class NameTag extends React.Component { componentWillMount() { this.setState({ name: this.props.name
}); } updateName(name) { this.setState({ name }); } render() { return ( <div> <p>Hello, my name is {this.state.name}</p> <p> <input type="text" value={this.state.name} onChange={e => this.updateName(e.target.value)} /> </p> </div> ); } } Intermingling view and behavior => Violating SRP
PROBLEMS PROPS FATIGUE
const App = ({ name, onChangeName }) => ( <AppDashboard
name={name} onChangeName={onChangeName}/> ); const AppDashboard = ({ name, onChangeName }) => ( <Dashboard> <Panel> <User name={name} onChangeName={onChangeName}/> </Panel> </Dashboard> ); const User = ({ name, onChangeName }) => ( <NameTag name={name} onChange={onChangeName}/> ); { name: 'Jeremy', onChangeName: (name) => { updateSomeGlobalState({ name }); } }
Wishlist • Manage state in one place outside of components
in a modular fashion. • Define behavior separate from view. • Inject props without deep passing. (Like partial application.)
+ Redux =
{ user: { name: 'Jeremy', email: '
[email protected]
', username: 'elpapapollo' }
} Store App
Provider & connect { user: { name: 'Jeremy', email: '
[email protected]
',
username: 'elpapapollo' } } Store App
{ name: 'Jet', type: 'UPDATE_NAME' } Action Provider & connect
{ user: { name: 'Jeremy', email: '
[email protected]
', username: 'elpapapollo' } } Store App Dispatch
{ name: 'Jet', type: 'UPDATE_NAME' } Action Provider & connect
{ user: { name: 'Jet', email: '
[email protected]
', username: 'elpapapollo' } } New Store State App Dispatch { user: { name: 'Jeremy', email: '
[email protected]
', username: 'elpapapollo' } } Store Reducer
<Demo> <ContactManager/> </Demo> Demo
Recap • Modularity • Modular React components • Modular Redux
reducers and state
Resources • facebook.github.io/react • redux.js.org • egghead.io/series/getting-started-with-redux
Jeremy Fairbank blog.jeremyfairbank.com @elpapapollo | github.com/jfairbank THANKS! Code: github.com/jfairbank/modular-react-and-redux-talk