मुख्य सामग्री पर जाएँ
Skillpedia
वेबसाइट और UI (frontend)33k · #9146

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 पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/SigNoz/signoz/blob/main/frontend/.cursor/skills/migrate-state-management/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

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:

  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
लाइसेंस
—
अपडेट की गई
2/11/2026

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

मिलती-जुलती skills