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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
190
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
どこまでゆるくて許されるのか
tk3fftk
0
520
Welcome to the "Parametricity" 🏙️ − Generic だけど Specific な世界 −
guvalif
PRO
1
180
アルゴリズムは何を圧縮しているのか ─ Haskell から育った「圧縮代数」というメンタルモデル
naoya
16
3.5k
鹿野さんに聞く!『TypeScriptコードレシピ集』で磨く実践力
tonkotsuboy_com
4
1.1k
「正の参照」と 「負の導出」で組む ハーネスエンジニアリング
cottpan
1
150
任せる範囲はこう広がった / How the Scope of AI Delegation Has Expanded
nrslib
1
270
共通化で考えるべきは、実装より公開する型だった
codeegg
0
270
AI駆動開発を妨げる技術的負債の解消アプローチ / ai-refactoring-approach
minodriven
17
9.2k
継続モナドとリアクティブプログラミング
yukikurage
3
620
はてなアカウント基盤 State of the Union
cockscomb
1
1.3k
ソフトウェア設計に溶けるインフラ ― AWS CDK のインフラ認識論
konokenj
2
600
AI 輔助遺留系統現代化的經驗分享
jame2408
1
1.2k
Featured
See All Featured
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
400
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
Writing Fast Ruby
sferik
630
63k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
410
Navigating Team Friction
lara
192
16k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
Testing 201, or: Great Expectations
jmmastey
46
8.2k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
390
Building Flexible Design Systems
yeseniaperezcruz
330
40k
Are puppies a ranking factor?
jonoalderson
1
3.7k
Statistics for Hackers
jakevdp
799
230k
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