SlideShare a Scribd company logo
State management in a GraphQL era
smoosh
“Rockstar developer”
Rockstar
Everything but a rockstar
“He rocked the stage”
He read his notes from a made-on-a-plane
slides trembling for 30 minutes while
praying that people won't out he’s a fraud
Rolling Stones in front of 1.5m people
 At the end of the day we're all code
monkeys trying to make weird libraries
work together by writing shitty hacks
🙈 🙉 🙊
I am Kitze $👋
(A Rockstar Senior Ninja Developer)
I am Kitze $ 👋
💖 Open Source
💖 Making products
💖 Frontend
React, React Native, Redux, MobX, GraphQL,
Apollo, CSS, css-in-js, etc.
reactacademy.io
const loginToMac = ({user, password}) => {
return user === 'root' && password === '';
}
Login in High Sierra
State management
in a GraphQL era
TL;DR
GraphQL is the thing that’s eventually
gonna replace REST, but you keep
telling yourself that you don’t need to
learn it.
REST
/api/currentUser/activity
/api/currentUser/friends
/api/user/5/activity
/api/user/5/likedPosts
GraphQL
query {
currentUser {
activity {
posts {
title
dateCreated
}
}
friends {
name
avatarUrl
activity {
likedPosts {
id
imageUrl
}
}
}
}
}
SPAs ruined everything
🤦
SPAs ruined everything
State management
Data
Forms
Routing
Tabs
NavigationMenus
Filters
Date pickers
Checkboxes
Inputs
Data is the #1 reason why
state management is hard
Data fetching
Caching
Reading
Cache invalidating
jQuery
JustAngular™
React
/api/posts
/api/posts/1
/api/user/info
Trying to be too smart
Redux
I love Redux
I hate Redux
State management in a GraphQL era
“Hello Reddit 👋 I just started my first React
app.
What should I use to do network requests?”
“Just use redux-saga”
Explaining Redux to someone
Right now, there is a poor soul
trying to connect redux-saga with redux-form
just to make a frickin’ login form
Explaining Redux to someone
MobX
jQuery vs MooTools
Angular vs Ember
GraphQL vs Rest
Redux vs MobX
React vs Vue
Apollo vs Relay
Hillary vs Trump
Mistake: Asking
❓what’s better❓
instead of
✅ what’s suitable for my app
✅ what’s suitable for my team
✅ what’s suitable for our use-case
Trump is great…
on a golf course.
HIGHER ORDER COMPONENTS SUCK !!!111 🤬
RENDER PROPZZ ARE EVERYYTHINNGG <3 <3
HOW ABOUT A HEALTHY MIX? 🍏
WE NEED REDUX FOR EVERYTHING !!!!1111
REDUX IS DEAD ☠
WE CAN JUST REPLACE IT WITH THE NEW
CONTEXT RIGHHTTT GUISE??!111 🙄
HOW ABOUT A HEALTHY MIX? 🍏
Examples
fetch('api/todos').then(function(response) {
return response.json();
}).then(function(todos) {
console.log(todos);
});
Fetch
const fetchTodos = () => dispatch => {
dispatch({type: 'FETCH_TODOS_INIT'});
api.fetchTodos().then(todos => {
dispatch({type: 'FETCH_TODOS_SUCCESS', todos});
}).catch(error => {
dispatch({type: 'FETCH_TODOS_FAIL', error})
})
};
Redux - async action
const todosReducer = (
state = {loading: false, todos: [], error: null},
action
) => {
switch (action.type) {
case 'FETCH_TODOS_INIT': {
return { ...state, loading: true};
}
case 'FETCH_TODOS_SUCCESS': {
return { ...state, loading: false, todos: action.todos};
}
case 'FETCH_TODOS_FAIL': {
return { ...state, loading: false, error: action.error};
}
}
};
Redux - reducer
class App {
@observable todos = [];
@observable loading = false;
@observable error = null;
@action fetchTodos = () => {
this.loading = true;
api.fetchTodos().then(todos => {
this.todos = todos;
this.loading = false;
}).catch(error => {
this.error = error;
this.loading = false;
});
}
}
MobX
GraphQL
@graphql(gql`
query {
todos {
title
date
}
}
`)
class Todos extends Component {
render(){
const {data: {loading, todos}} = this.props;
{loading ? <div> loading ... </div> : <ul>
{todos.map(todo => <li>{todo.title} - {todo.date} </li>)}
</ul>}
}
}
GraphQL
We were fixing the sink
instead of the well
the sink = state management
the well = REST apis
State management
Data
Forms
Routing
Tabs
NavigationMenus
Filters
Date pickers
Checkboxes
Inputs
State management
Forms
Routing
Tabs
NavigationMenus
Filters
Date pickers
Checkboxes
Inputs
State management in a GraphQL era
Do we even need a state
management library when using
GraphQL?
1. Vanilla
2. I hate forms
3. My users live in tunnels
4. I wanna go home early
5. Next level
6. Apollo
- Apollo
- Router library
🍦Vanilla
- setState()
- Apollo
- Router library
😡 I hate forms
- Form library
- setState()
- Apollo
- Router library
🚅 My users live in tunnels
- apollo-cache-persist
- Apollo
- MobX
🏡 I wanna go home early
- mobx-router
- mobx-react-form
- Apollo
- Next.js
🔺 Next level
- setState()
🔺 Next level 2.0
Use full page reloads when
navigating between routes
Treat every route as a separate mini-app
😱
/
/about
/products
/product/123 /cart
App 1
App 2
App 4
App3
App5
Only Apollo?
apollo-link-state
Client side schema
@graphql(gql`
query {
todos {
title
completed
date
}
counter @client
}
`)
class Todos extends Component {
render() {
}
}
When using GraphQL, in 90% of the
cases, you won’t need Redux, MobX,
sagas, observables, RxJS or *insert
hipster state-management library here*
But who am I to tell you what to do?!
I work alone
I don’t work for clients
I experiment with a new library every week
I don’t know what I’m doing
I’ll make a Christmas tree out of this slide
Evaluate the context,
and your situation, before you follow
other people’s advice
A client project story
Don’t be scared of the network!
Few kilobytes of data
are better than your team spending
weeks on overengineering things.
I used to overengineer things in my past.
Now I’m just trying to make my users
happy 💜
🖐
✅ I made something
✅ It works and I think it’s awesome
😞 I’m not sure if it’s right
What is “right”?
Router example(s)
Nomadlist example(s)
A hospital website
🤦 🤦 🤦 🤦 🤦 🤦 🤦 🤦 🤦 🤦 🤦 🤦
Don’t feel bad for not using the
latest and greatest
Service worker example
🖐
Stop seeking external approval 🙏
Stop seeking answers in other people’s projects 👪
Stop feeling insecure about your code because
nobody actually knows what they’re doing 😕
For God’s sake delete your Twitter account 🙅
If you like what you’re doing and it works
for you, please forget about this talk
and move on.
✅ kitze.io
😞 @thekitze on Twitter
✅ @kitze on GitHub
✅ @kitze on Medium
Thank you 🙏
@thekitze
reactacademy.io
@kitze
@kitze

More Related Content

PDF
Callbacks and control flow in Node js
Thomas Roch
 
PDF
Tdc 2013 - Ecossistema Ruby
Fabio Akita
 
PPTX
Avoiding Callback Hell with Async.js
cacois
 
PPTX
Javascript asynchronous
kang taehun
 
PDF
非同期javascriptの過去と未来
Taketoshi 青野健利
 
PPTX
GvaScript Library
Mona Remlawi
 
PDF
Kotlin wonderland
Jedsada Tiwongvokul
 
ODP
Building serverless application on the Apache Openwhisk platform
Lucio Grenzi
 
Callbacks and control flow in Node js
Thomas Roch
 
Tdc 2013 - Ecossistema Ruby
Fabio Akita
 
Avoiding Callback Hell with Async.js
cacois
 
Javascript asynchronous
kang taehun
 
非同期javascriptの過去と未来
Taketoshi 青野健利
 
GvaScript Library
Mona Remlawi
 
Kotlin wonderland
Jedsada Tiwongvokul
 
Building serverless application on the Apache Openwhisk platform
Lucio Grenzi
 

What's hot (20)

PDF
objection - runtime mobile exploration
SensePost
 
PDF
Functional Reactive Programming / Compositional Event Systems
Leonardo Borges
 
PPTX
Avoiding callback hell in Node js using promises
Ankit Agarwal
 
PDF
Messaging with the Docker
Henryk Konsek
 
PDF
Callbacks, promises, generators - asynchronous javascript
Łukasz Kużyński
 
PDF
ECMAScript 6
偉格 高
 
PDF
Asynchronous and event-driven Grails applications
Alvaro Sanchez-Mariscal
 
PDF
Asynchronous Programming FTW! 2 (with AnyEvent)
xSawyer
 
PDF
Présentation de HomeKit
CocoaHeads France
 
PDF
G*なクラウド 雲のかなたに ショートバージョン
Tsuyoshi Yamamoto
 
PDF
High Performance web apps in Om, React and ClojureScript
Leonardo Borges
 
PDF
Asynchronous programming done right - Node.js
Piotr Pelczar
 
PDF
Grunt.js introduction
Claudio Mignanti
 
PDF
G*なクラウド ~雲のかなたに~
Tsuyoshi Yamamoto
 
PDF
Puppet and Openshift
Gareth Rushgrove
 
PDF
Introducing Middy, Node.js middleware engine for AWS Lambda (FrontConf Munich...
Luciano Mammino
 
PDF
Serverless, The Middy Way - Workshop
Luciano Mammino
 
PPTX
Real world functional reactive programming
Eric Polerecky
 
PDF
CLS & asyncListener: asynchronous observability for Node.js
Forrest Norvell
 
PDF
Functional Reactive Programming in Clojurescript
Leonardo Borges
 
objection - runtime mobile exploration
SensePost
 
Functional Reactive Programming / Compositional Event Systems
Leonardo Borges
 
Avoiding callback hell in Node js using promises
Ankit Agarwal
 
Messaging with the Docker
Henryk Konsek
 
Callbacks, promises, generators - asynchronous javascript
Łukasz Kużyński
 
ECMAScript 6
偉格 高
 
Asynchronous and event-driven Grails applications
Alvaro Sanchez-Mariscal
 
Asynchronous Programming FTW! 2 (with AnyEvent)
xSawyer
 
Présentation de HomeKit
CocoaHeads France
 
G*なクラウド 雲のかなたに ショートバージョン
Tsuyoshi Yamamoto
 
High Performance web apps in Om, React and ClojureScript
Leonardo Borges
 
Asynchronous programming done right - Node.js
Piotr Pelczar
 
Grunt.js introduction
Claudio Mignanti
 
G*なクラウド ~雲のかなたに~
Tsuyoshi Yamamoto
 
Puppet and Openshift
Gareth Rushgrove
 
Introducing Middy, Node.js middleware engine for AWS Lambda (FrontConf Munich...
Luciano Mammino
 
Serverless, The Middy Way - Workshop
Luciano Mammino
 
Real world functional reactive programming
Eric Polerecky
 
CLS & asyncListener: asynchronous observability for Node.js
Forrest Norvell
 
Functional Reactive Programming in Clojurescript
Leonardo Borges
 
Ad

Similar to State management in a GraphQL era (20)

PDF
GraphQL over REST at Reactathon 2018
Sashko Stubailo
 
PDF
React lecture
Christoffer Noring
 
PPTX
Redux vs GraphQL
Jordon McKoy
 
PDF
Introduction to GraphQL (or How I Learned to Stop Worrying about REST APIs)
Hafiz Ismail
 
PPT
Graphql presentation
Vibhor Grover
 
PDF
Tokyo React.js #3: Missing Pages: ReactJS/Flux/GraphQL/RelayJS
Khor SoonHin
 
PDF
Fly me to the moon
Fatos Hoti
 
PDF
Why UI developers love GraphQL
Sashko Stubailo
 
PDF
Why UI Developers Love GraphQL - Sashko Stubailo, Apollo/Meteor
Jon Wong
 
PDF
Sexy React Stack
KMS Technology
 
PDF
Michelle Garrett - Build the API you want to see in the world (with GraphQL) ...
Codemotion
 
PDF
Michelle Garrett - Build the API you want to see in the world (with GraphQL) ...
Codemotion
 
PDF
GraphQL vs. (the) REST
coliquio GmbH
 
PDF
JS Fest 2019/Autumn. Alexandre Gomes. Embrace the "react fatigue"
JSFestUA
 
PPTX
React Flux to GraphQL
Turadg Aleahmad
 
PPTX
GraphQL, Redux, and React
Keon Kim
 
PDF
React state management with Redux and MobX
Darko Kukovec
 
PPTX
GraphQL - Tidepool Labs
Harutyun Abgaryan
 
PDF
Boosting Data Fetching in Turkish Apps with React Native and GraphQL
Shiv Technolabs Pvt. Ltd.
 
PPTX
Build the API you want to see in the world
Michelle Garrett
 
GraphQL over REST at Reactathon 2018
Sashko Stubailo
 
React lecture
Christoffer Noring
 
Redux vs GraphQL
Jordon McKoy
 
Introduction to GraphQL (or How I Learned to Stop Worrying about REST APIs)
Hafiz Ismail
 
Graphql presentation
Vibhor Grover
 
Tokyo React.js #3: Missing Pages: ReactJS/Flux/GraphQL/RelayJS
Khor SoonHin
 
Fly me to the moon
Fatos Hoti
 
Why UI developers love GraphQL
Sashko Stubailo
 
Why UI Developers Love GraphQL - Sashko Stubailo, Apollo/Meteor
Jon Wong
 
Sexy React Stack
KMS Technology
 
Michelle Garrett - Build the API you want to see in the world (with GraphQL) ...
Codemotion
 
Michelle Garrett - Build the API you want to see in the world (with GraphQL) ...
Codemotion
 
GraphQL vs. (the) REST
coliquio GmbH
 
JS Fest 2019/Autumn. Alexandre Gomes. Embrace the "react fatigue"
JSFestUA
 
React Flux to GraphQL
Turadg Aleahmad
 
GraphQL, Redux, and React
Keon Kim
 
React state management with Redux and MobX
Darko Kukovec
 
GraphQL - Tidepool Labs
Harutyun Abgaryan
 
Boosting Data Fetching in Turkish Apps with React Native and GraphQL
Shiv Technolabs Pvt. Ltd.
 
Build the API you want to see in the world
Michelle Garrett
 
Ad

Recently uploaded (20)

PPTX
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PDF
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PPTX
Simple and concise overview about Quantum computing..pptx
mughal641
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
The Future of Artificial Intelligence (AI)
Mukul
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PPTX
The Future of AI & Machine Learning.pptx
pritsen4700
 
PDF
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
PDF
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
Simple and concise overview about Quantum computing..pptx
mughal641
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
The Future of Artificial Intelligence (AI)
Mukul
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
The Future of AI & Machine Learning.pptx
pritsen4700
 
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 

State management in a GraphQL era