sharing-state-and-functions-via-context-slides
sharing-state-and-functions-via-context-slides
Context
Cory House
React Consultant and Trainer
@housecor | reactjsconsulting.com
Agenda
Why context?
Use context to share our cart
- Wrap provider in a custom component
- Share context via a custom hook
Do I need context?
Plain JS React React Context Redux
Simple Complex
No setup Significant setup
What if components in different parts of your app need the same data?
User data
User data
3 Solutions
1. Lift State
User data
User data
3 Solutions
1. Lift State
2. React context
UserContext.Provider
(Holds user data and funcs)
Call createUser via context
UserContext.Consumer
UserContext.Consumer
3 Solutions
1. Lift State
2. React context Store
3. Redux
Many actions
My Take