"매 state = 매 program 의 매 time 의 매 snapshot". 매 변하는 모든 데이터 — 매 UI 의 input value, 매 server 의 user session, 매 game 의 entity transform 까지. 매 state management 가 매 software complexity 의 매 dominant source — Rich Hickey 의 famous "state is hard" quote (Strange Loop 2009).
매 핵심
매 분류
Local / component state: 매 React useState, 매 Vue ref — 매 single component scope.
Shared / global state: 매 Redux/Zustand/Pinia/Jotai — 매 multiple components share.
Server state: 매 React Query/TanStack Query/SWR — 매 server-of-truth 의 매 cache.
URL state: 매 query params, hash — 매 shareable / bookmarkable.
Persistent state: 매 localStorage, IndexedDB, DB — 매 across sessions.
Derived state: 매 computed from base state — 매 NOT stored separately (single source of truth).
매 state 의 trade-off
매 mutable vs 매 immutable: 매 immutability → 매 reasoning easier, 매 time-travel debug 가능, 매 perf cost 일부.
매 local vs 매 global: 매 global → 매 sharing easy, 매 coupling explosion.
매 client vs 매 server: 매 client → 매 latency 0, 매 inconsistency. 매 server → 매 truth 1, 매 latency.
매 fine-grained vs 매 coarse: 매 fine → 매 selective re-render, 매 bookkeeping cost.
import{useQueryState,parseAsInteger}from"nuqs";functionProductList() {const[page,setPage]=useQueryState("page",parseAsInteger.withDefault(1));const[sort,setSort]=useQueryState("sort",{defaultValue:"name"});// 매 URL = ?page=2&sort=price → 매 shareable, 매 back-button works.
}
Pattern 5: Derived state (NEVER duplicate base)
// 매 BAD — 매 fullName 의 매 별도 state.
const[first,setFirst]=useState("");const[last,setLast]=useState("");const[fullName,setFullName]=useState("");// 매 anti-pattern
// 매 GOOD — 매 derive on render.
constfullName=`${first}${last}`;// 매 expensive case → useMemo.
constexpensiveResult=useMemo(()=>heavyCompute(first,last),[first,last]);
Pattern 6: State machine (XState)
import{setup}from"xstate";consttrafficLight=setup({}).createMachine({initial:"red",states:{red:{on:{TICK:"green"}},green:{on:{TICK:"yellow"}},yellow:{on:{TICK:"red"}},},});// 매 invalid transition 의 매 compile-time prevention.
매 결정 기준
상황
Approach
매 component-local UI
useState
매 2-3 component shared
Lift state up / Context
매 app-wide global
Zustand / Jotai
매 server data
TanStack Query (NOT global state)
매 form
React Hook Form + Zod
매 URL-bound
nuqs / TanStack Router
매 complex transitions
XState (state machine)
매 persistent
Zustand persist middleware / IndexedDB
기본값: 매 derive whenever possible. 매 store 만 base state. 매 server state 의 매 global state X (TanStack Query 사용).