본문으로 건너뛰기
Skillpedia
웹사이트 및 UI (프런트엔드)33k · #9146

migrate-state-management

하는 일

이 스킬은 React 앱의 상태 관리를 Redux와 React Context에서 벗어나도록 리팩터링하는 과정을 AI 에이전트에게 안내합니다. 프론트엔드 상태 코드를 현대화하는 개발자를 위한 스킬입니다.

사용하는 경우

  • ✓Redux나 React Context를 없애고 데이터 조회 상태를 React Query로 옮기고 싶을 때.
  • ✓필터나 기간을 공유할 수 있도록 URL에 두고 싶어 nuqs를 쓰고 싶을 때.
  • ✓전역 클라이언트 상태에 더 단순한 자리가 필요해 Zustand로 옮기고 싶을 때.

스킬 링크

https://github.com/SigNoz/signoz/blob/main/frontend/.cursor/skills/migrate-state-management/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/SigNoz/signoz/blob/main/frontend/.cursor/skills/migrate-state-management/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“Redux 스토어의 API 데이터는 React Query로 옮기고, 필터는 URL에 유지해 주실 수 있나요?”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

에이전트는 각 상태를 서버 상태, URL 상태, 전역 클라이언트 상태로 분류한 뒤, 각 상태를 맞는 도구로 옮깁니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

Migrate State: Redux/Context → React Query, nuqs, Zustand

Do not introduce or recommend Redux or React Context. Migrate existing usage to the stack below.

1. Classify the state

Before changing code, classify what the state represents:

If the state is… Migrate to Do not use
From API / server (versions, configs, fetched lists, time-series) React Query Redux, Context
Shareable via URL (filters, time range, page, selected ids) nuqs Redux, Context
Global/client UI (dashboard lock, query builder, feature flags, large client objects) Zustand Redux, Context
Local to one component (inputs, toggles, hover) useState / useReducer Zustand, Redux, Context

If one slice mixes concerns (e.g. Redux has both API data and pagination), split: API → React Query, pagination → nuqs, rest → Zustand or local state.

2. Migrate to React Query (server state)

When: State comes from or mirrors an API response (e.g. currentVersion, latestVersion, configs, lists).

Steps:

  1. Find where the data is fetched (existing useQuery/API call) and where it is dispatched or set in Context/Redux.
  2. Remove the dispatch/set that writes API results into Redux/Context.
  3. Expose a single hook that uses the query and returns the same shape consumers expect (use useMemo for derived objects like configs to avoid unnecessary re-renders).
  4. Replace Redux/Context consumption with the new hook. Prefer generated React Query hooks from frontend/src/api/generated when available.
  5. Configure cache/refetch (e.g. refetchOnMount: false, staleTime) so behavior matches previous “single source” expectations.

Before (Redux mirroring React Query):

if (getUserLatestVersionResponse.isFetched && getUserLatestVersionResponse.isSuccess && getUserLatestVersionResponse.data?.payload) {
  dispatch({ type: UPDATE_LATEST_VERSION, payload: { latestVersion: getUserLatestVersionResponse.data.payload.tag_name } })
}

After (single source in React Query):

export function useAppStateHook() {
  const { data, isError } = useQuery(...)
  const memoizedConfigs = useMemo(() => ({ ... }), [data?.configs])
  return {
    latestVersion: data?.payload?.tag_name,
    configs: memoizedConfigs,
    isError,
  }
}

Consumers use useAppStateHook() instead of useSelector or Context. Do not copy React Query result into Redux or Context.

3. Migrate to nuqs (URL / shareable state)

When: State should be in the URL: filters, time range, pagination, selected values, view state. Keep payload small (e.g. Chrome ~2k chars); no large datasets or sensitive data.

Steps:

  1. Identify which Redux/Context fields are shareable or already reflected in the URL (e.g. currentPage, timeRange, selectedFilter).
  2. Add nuqs (or use existing): useQueryState('param', parseAsString.withDefault('…')) (or parseAsInteger, etc.).
  3. Replace reads/writes of those fields with nuqs hooks. Use typed parsers; avoid ad-hoc useSearchParams encoding/decoding.
  4. Remove the same fields from Redux/Context and their reducers/providers.

Before (Context/Redux):

const { timeRange } = useContext(SomeContext)
const [page, setPage] = useDispatch(...)

After (nuqs):

const [timeRange, setTimeRange] = useQueryState('timeRange', parseAsString.withDefault('1h'))
const [page, setPage] = useQueryState('page', parseAsInteger.withDefault(1))

4. Migrate to Zustand (global client state)

When: State is global or cross-component client state: feature flags, dashboard state, query builder state, complex/large client objects (e.g. up to ~1.5–2MB). Not for server cache or local-only UI.

Steps:

  1. Create one store per domain (e.g. DashboardStore, QueryBuilderStore). One create() per module; for large state use slice factories and combine.
  2. Put state properties first, then actions. Use set (or setState / getState() + set) for updates; never mutate state directly.
  3. Replace Context/Redux consumption with the store hook and a selector so only the used slice triggers re-renders.
  4. Remove the old Context provider / Redux slice and related dispatches.

Selector (required):

const isLocked = useDashboardStore(state => state.isDashboardLocked)

Never use useStore() with no selector. Never do state.foo = x inside actions; use set(state => ({ ... })).

Before (Context/Redux):


자주 묻는 질문

왜 Redux를 유지하지 않나요?

스킬은 Redux나 React Context를 새로 도입하거나 추천하지 말고, 기존 사용도 옮기라고 말합니다.

nuqs는 무엇을 다루나요?

필터, 페이지, 선택한 항목처럼 URL로 공유되어야 하는 상태를 다룹니다.

로컬 상태는 어떻게 하나요?

한 컴포넌트에만 속한 상태는 useState나 useReducer를 써야 합니다.

상세 정보

작성자의 원본 설명

Migrate Redux or React Context to the correct state option (React Query for server state, nuqs for URL/shareable state, Zustand for global client state). Use when refactoring away from Redux/Context, moving state to the right store, or when the user asks to migrate state management.

repo: SigNoz/signoz

인기도

GitHub 스타
33k
순위
#9146
라이선스
—
업데이트
2026. 11. 2.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬