7th Practical Class:
Context, More Hooks, Debugging, and GraphQL Fragments
- React Context
- Some More Hooks
- Debugging
- GraphQL Fragments
- Fragments with Apollo Client
React Context
Props Drilling
React Context and useContext Hook
Nested Context Providers
useContext Without Context Provider
Create Context:
Provide Context Value:
Get Context Value:
Who is Using Context?
libraries:
- Apollo Client (
useQuery,useMutation, ...) - Formik (
useField,Field,Form, ...) - React Router
- Apollo Client (
Quacker / Team Projects
👌 Please read: How to use React Context effectively 👌
Some More Hooks
useMemo,useCallback- Custom Hooks
useRef(focus)useReducer- link
useMemo, useCallback
Whithout Memoization:
With Memoization:
Custom Hooks
- see Building Your Own Hooks
- use
use*prefix!
useRef
useReducer
- "more powerfull
useState" - see How to use React Context effectively
useReducerdocumentation- good candidate for Pomodoro timers
Debugging
console.log()- use:
console.log("something:", value1, value2)
- use:
debugger- JavaScript Source Maps
- Chrome extensions:
GraphQL Fragments
- With fragments: