Menu

When Does Local State Become Shared State? A React State Ownership Guide
📰

When Does Local State Become Shared State? A React State Ownership Guide

DEV Community: typescript·KhaledSalem·5 days ago
#BxzJDSX8
#devtotypescript#devto#dev#state#checkout
Reading 0:00
15s threshold

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…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.