
Published on May 02, 2025 by Eunbi.N
Zustand React Query State Management Server State React
Zustand (Client State): 애플리케이션 로컬 상태
React Query (Server State): 서버 데이터 상태
Zustand: 간단한 스토어 패턴
create() 함수로 스토어 생성, set(), get() 메서드 사용React Query: 선언적 쿼리 훅
useQuery(), useMutation() 훅 기반 데이터 페칭Zustand: 수동 캐싱 관리
persist 미들웨어로 로컬 스토리지 연동React Query: 자동 캐싱 시스템
Zustand: 수동 동기화
React Query: 자동 백그라운드 동기화
Zustand + React Query: 완전한 상태 관리 솔루션
사용 예시:
// Zustand - 클라이언트 상태
const useAppStore = create((set) => ({
theme: "light",
sidebarOpen: false,
toggleTheme: () =>
set((state) => ({
theme: state.theme === "light" ? "dark" : "light",
})),
}));
// React Query - 서버 상태
const { data: users, isLoading } = useQuery({
queryKey: ["users"],
queryFn: fetchUsers,
});