migrate-state-management
यह क्या करती है
यह स्किल AI एजेंट को React ऐप में Redux और React Context से दूर जाकर स्टेट प्रबंधन की refactoring में मार्गदर्शन देती है। यह अपने स्टेट कोड को आधुनिक बनाने वाले फ़्रंट-एंड डेवलपर के लिए है।
कब इस्तेमाल करें
- ✓जब आप Redux या React Context हटाकर डेटा लाने वाली स्टेट React Query में ले जाना चाहें।
- ✓जब कोई फ़िल्टर या समय-सीमा URL में रहनी चाहिए, ताकि उसे साझा किया जा सके, और आप nuqs इस्तेमाल करना चाहें।
- ✓जब ग्लोबल क्लाइंट स्टेट को सरल ठिकाने की ज़रूरत हो और आप उसे Zustand में ले जाना चाहें।
Skill का लिंक
https://github.com/SigNoz/signoz/blob/main/frontend/.cursor/skills/migrate-state-management/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“क्या आप हमारे Redux store का API डेटा React Query में ले जा सकते हैं और फ़िल्टर URL में रख सकते हैं?”
हर हफ़्ते 5 नई skills, 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 में साझा होना चाहिए, जैसे फ़िल्टर, पेज और चुने गए आइटम।
लोकल स्टेट के बारे में क्या?
जो स्टेट केवल एक कंपोनेंट की है, उसे 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
- लाइसेंस
- —
- अपडेट की गई
- 2/11/2026
कमेंट
- …
इस repository की और skills
मिलती-जुलती skills
angular-developer
280kआपके एजेंट को Angular code बनाने और प्रोजेक्ट स्ट्रक्चर पर सलाह देने में मदद करता है। नए प्रोजेक्ट शुरू करने, code के हिस्से बनाने, या performance और accessibility सुधारने में उपयोगी है।
frontend-a11y
280kआपके एजेंट को web interfaces को सबके लिए accessible बनाने में मदद करता है। यह सुनिश्चित करता है कि websites और apps screen readers और keyboard navigation के साथ अच्छे से काम करें।
frontend-patterns
280kआपके एजेंट को React और Next.js में frontend development के modern patterns लागू करने में मदद करता है। यह performance optimize करता है, state manage करता है और best practices फॉलो करवाता है।