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

GraphQL_Summit_2019.pdf

 GraphQL_Summit_2019.pdf

Shruti Kapoor

October 30, 2019
Tweet

More Decks by Shruti Kapoor

Other Decks in Programming

Transcript

  1. • React Component State • ContextAPI • Redux • Mobx

    • mobx-state-tree • Hooks • Apollo Client Different ways of managing state @shrutikapoor08
  2. • React Component State • ContextAPI • Redux • Mobx

    • mobx-state-tree •Hooks • Apollo Client Different ways of managing state @shrutikapoor08
  3. Good Redux Bad • Connect function to share data magically

    • No prop drilling • All state - local and global in store • Huge boilerplate
  4. Good Context Provider Bad • Lifts state up • No

    prop drilling • All components that consume a provider are updated.
  5. • Update DOM • Accepts a func with effectful code

    • Similar to componentDidMount useEffect • Replaces this.state • Use for shared components • Initialize state and auto-update useState React Hooks
  6. 1. Initialize your state ( initialState ) 2. Call useReducer

    with the initialState. 3. Figure out which top level component should have context and setup context.
  7. 1. Initialize your state ( initialState ) 2. Call useReducer

    with the initialState. 3. Figure out which top level component should have context and setup context. 4. Pass in the dispatch returned from useReducer to the Context provider API so that children have access to dispatch.
  8. 1. Initialize your state ( initialState ) 2. Call useReducer

    with the initialState. 3. Figure out which top level component should have context and setup context. 4. Pass in the dispatch returned from useReducer to the Context provider API so that children have access to dispatch. 5. Hook up Graphql API to a component using useEffect.
  9. 1. Initialize your state ( initialState ) 2. Call useReducer

    with the initialState. 3. Figure out which top level component should have context and setup context. 4. Pass in the dispatch returned from useReducer to the Context provider API so that children have access to dispatch. 5. Hook up Graphql API to a component using useEffect. 6. Use useContext and useReducer to receive and update global application state.
  10. 1. Initialize your state ( initialState ) 2. Call useReducer

    with the initialState. 3. Figure out which top level component should have context and setup context. 4. Pass in the dispatch returned from useReducer to the Context provider API so that children have access to dispatch. 5. Hook up Graphql API to a component using useEffect. 6. Use useContext and useReducer to receive and update global application state. 7. Use useState for local state.