State Management Decision Authority — Part 02
Your React state doesn't need to be global just because two components need it.
In Part 1, useState vs useReducer: Stop Choosing Tools Before Understanding State , I explored an architectural idea I call the State Management Decision Authority : choosing state management strategies through consistent criteria rather than tool preferences.
One of those criteria deserves a deeper discussion:
State Ownership.
Because sharing state and globalizing state are two very different decisions.
1. The Checkout Problem
Imagine a checkout feature with three components:
function Checkout () { return ( <> < ShippingForm /> < OrderSummary /> < PaymentSection /> </> ); }
Enter fullscreen mode
Exit fullscreen mode
Each component has a different responsibility.
ShippingForm collects the delivery address.
OrderSummary displays the shipping cost.
PaymentSection checks whether checkout requirements are satisfied.
But they all depend on some of the same information.
If…