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がスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
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:
- Find where the data is fetched (existing
useQuery/API call) and where it is dispatched or set in Context/Redux. - Remove the dispatch/set that writes API results into Redux/Context.
- Expose a single hook that uses the query and returns the same shape consumers expect (use
useMemofor derived objects likeconfigsto avoid unnecessary re-renders). - Replace Redux/Context consumption with the new hook. Prefer generated React Query hooks from
frontend/src/api/generatedwhen available. - 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:
- Identify which Redux/Context fields are shareable or already reflected in the URL (e.g.
currentPage,timeRange,selectedFilter). - Add nuqs (or use existing):
useQueryState('param', parseAsString.withDefault('…'))(orparseAsInteger, etc.). - Replace reads/writes of those fields with nuqs hooks. Use typed parsers; avoid ad-hoc
useSearchParamsencoding/decoding. - 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:
- Create one store per domain (e.g.
DashboardStore,QueryBuilderStore). Onecreate()per module; for large state use slice factories and combine. - Put state properties first, then actions. Use
set(orsetState/getState()+set) for updates; never mutate state directly. - Replace Context/Redux consumption with the store hook and a selector so only the used slice triggers re-renders.
- 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で共有できるべき状態を扱います。
ローカルの状態はどうしますか?
1つのコンポーネントに属する状態は、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
コメント
- …
このリポジトリの他のスキル
似ているスキル
angular-developer
280kエージェントがAngularのコードを作成し、プロジェクト構成についてアドバイスできるようにします。新しいプロジェクトの開始、コード部品の作成、パフォーマンスやアクセシビリティの改善に役立ちます。
frontend-a11y
280kエージェントが Web インターフェースを誰にとっても使いやすくするよう支援します。スクリーンリーダーやキーボード操作に対応し、サイトやアプリが適切に動作するようにします。
frontend-patterns
280kエージェントがフロントエンド開発の最新パターンを適用できるようにします。React と Next.js において、パフォーマンスの最適化、状態管理、ベストプラクティスの遵守を行います。