Upgrade to Pro — share decks privately, control downloads, hide ads and more …

React State - The Good, the Bad and the Ugly - ...

React State - The Good, the Bad and the Ugly - ArmadaJS

Ivan Jovanovic

October 19, 2019
Tweet

More Decks by Ivan Jovanovic

Other Decks in Technology

Transcript

  1. Ivan: Hey man, how's life? Bob: All good! You need

    to see this cool project we are working on! Ivan: Awesome, what is it about? Bob: It's great, we are using this awesome stack with React, Mobx, Graphql running on AWS Lambda Ivan: Sounds interesting. What is project about? Bob: Ah right, we are building a blog for a real estate company.
  2. WHAT DO WE SEE HERE? • Text • Pictures •

    Links • Input fields • Buttons
  3. STATE TYPES • Application State (also known as Program State)

    represents the totality of everything necessary to keep your application running • Resource State refers to the state of the resources being stored on the server. These can be files, images, database records, etc. • Session State keeps track of user interaction during a browser session
  4. TECHCRUNCH DISRUPT SAN FRANCISCO - SEPTEMBER 2012. Mark Zuckerberg: "Our

    Biggest Mistake Was Betting Too Much On HTML5".
  5. HISTORY OF REACT STATE • Component State • Flux •

    Redux • GraphQL (Relay) • MobX • React 16 - Context API / React Hooks
  6. COMPONENT STATE PROS • Comes with React • Every component

    has it out of the box • Easy to use • Easy to learn
  7. COMPONENT STATE CONS • Hard to exchange state between components

    • Hard to update state from another component • Complicate to maintain when app becomes big
  8. FLUX PROS • Simple data flow • Unidirectional data flow

    • Easily handling data across components • Components listen to the store and react on changes
  9. REDUX PROS • Simple data flow • Unidirectional data flow

    • Easily handling data across components • Components listen to the store and react on changes • One store • Immutable store • No dispatcher
  10. RELAY PROS • Made for data-driven applications • Simple data

    flow • Descriptive components • Solves client-server data flow
  11. MOBX PROS • Reactive programming, everything is a stream (observable)

    • Store can do anything • No boilerplate • No middlewares
  12. MOBX CONS • No specific standard, anyone can use anything,

    too much freedom • Reactive programming is hard • Sometimes is really hard to debug
  13. CONCLUSION • Pick wisely, based on the size of the

    project and previous knowledge • Popular doesn't always mean the best • Learn the basics (how does setState work) • Combine (if needed) • Every new package for handling state was built to fix something. But, can we have a perfect package for state?