Deciding How To Handle State Slides
Deciding How To Handle State Slides
Cory House
React Consultant and Trainer
@housecor | reactjsconsulting.com
Version Check
This course was created by using:
- React 18
- React Router 6
Version Check
Understand JSX
Know how to declare a component
Mostly function components
Patterns presented work in classes too
Initial Release
2015 2018
Class only
Redux Context API
Experimental context
Initial Release
2015 2018
Class only
Redux Context API
Experimental context
Initial Release
2015 2018
Class only
Redux Context API
Experimental context
Initial Release
2015 2018
Class only
Redux Context API
Experimental context
Initial Release
2015 2018
Class only
Redux Context API
Experimental context
Initial Release
2015 2018
Class only
Redux Context API
Experimental context
URL
Web storage
Local state
Lifted state
Derived state
Refs
Context
Watch out
- Tied to a single browser
- Avoid storing sensitive data
Examples
- Items in shopping cart
- Partially completed form data
Option 3: Local State
Example
- Forms
- Toggles
- Local lists
Option 4: Lifted State
1. DOM reference
- Uncontrolled components
- Interfacing with non-React libraries
2. State that isn’t displayed
- Track if component is mounted
- Hold timer
- Store previous state value
Option 7: Context
General options
- Redux
- Mobx
- Recoil
Remote State
- react-query
- Swr
- Relay
- Apollo
Eight Ways to Handle React State
Summary
A History of React State
Initial Release
Aug 2015 Mar 2018
Class only
Redux Context API
Experimental context