Redux Toolkit / Zustand Interview Questions Hindi mein

Redux Toolkit / Zustand कोर्स के 25 सवाल, हर सवाल के सही जवाब और explanation के साथ। जवाब देखने से पहले ख़ुद सोचें।

State Management Foundations

1. Which is best described as server state?

  1. The text typed in a search box
  2. Whether a modal is open
  3. A list of orders fetched from an API that may become stale
  4. A theme preference that never leaves the browser
जवाब देखें

जवाब: A list of orders fetched from an API that may become stale

Server state is a cache of data owned elsewhere, so it needs fetching, invalidation and refetching.

पाठ: Local, Server and Global Client State

2. For data fetched from a REST API with caching and refetch needs, what is usually the best fit?

  1. A server-cache library such as TanStack Query or RTK Query
  2. A hand-written Redux reducer for every endpoint
  3. React Context with useState
  4. localStorage
जवाब देखें

जवाब: A server-cache library such as TanStack Query or RTK Query

Server-cache libraries handle loading flags, deduplication, staleness and invalidation for you.

पाठ: When You Need a Store

3. Why do Redux and Zustand rely on immutable updates?

  1. So the server can validate the state
  2. Because JavaScript objects cannot be mutated
  3. To make state smaller in memory
  4. So changes can be detected with a cheap reference comparison
जवाब देखें

जवाब: So changes can be detected with a cheap reference comparison

A new reference signals that something changed.

पाठ: Unidirectional Data Flow and Immutability

Redux Toolkit Core

4. What does configureStore add by default?

  1. A REST client
  2. Thunk middleware, dev-mode checks and DevTools integration
  3. Persistence to localStorage
  4. Server-side rendering
जवाब देखें

जवाब: Thunk middleware, dev-mode checks and DevTools integration

Sensible defaults are the point of configureStore.

पाठ: configureStore

5. Why can createSlice reducers write state.items.push(x)?

  1. Redux allows mutation since version 2
  2. They run inside Immer, which turns draft mutations into an immutable update
  3. push is overridden by Redux
  4. The state is deep-cloned before every action
जवाब देखें

जवाब: They run inside Immer, which turns draft mutations into an immutable update

Immer tracks changes to a draft.

पाठ: createSlice, Actions and Immer

6. When does a component using useSelector re-render?

  1. Only when the Provider remounts
  2. On every dispatched action, always
  3. Only when its props change
  4. When the selected value changes by reference (===)
जवाब देखें

जवाब: When the selected value changes by reference (===)

useSelector compares the previous and next selected values.

पाठ: Provider, useSelector and useDispatch

Async Logic in Redux

7. Which actions can a createAsyncThunk dispatch for one call?

  1. pending, then either fulfilled or rejected
  2. start and end only
  3. request, success, failure and retry
  4. Only fulfilled
जवाब देखें

जवाब: pending, then either fulfilled or rejected

The lifecycle actions are generated automatically.

पाठ: createAsyncThunk Lifecycle

8. What does .unwrap() on a dispatched thunk result do?

  1. Cancels the request
  2. Removes the thunk from the store
  3. Returns the fulfilled payload or throws the rejection
  4. Converts the thunk into a slice reducer
जवाब देखें

जवाब: Returns the fulfilled payload or throws the rejection

unwrap lets components use try/catch around a thunk.

पाठ: Loading and Error State

9. Where should an autosave network call triggered by an action live in RTK?

  1. Inside the selector
  2. Inside the slice reducer
  3. In a listener middleware effect or a thunk
  4. In initialState
जवाब देखें

जवाब: In a listener middleware effect or a thunk

Reducers must stay pure; effects go in middleware.

पाठ: Listener Middleware and Side Effects

RTK Query

10. What does RTK Query generate from a getPosts query endpoint?

  1. A useGetPostsQuery React hook
  2. A REST server
  3. A database migration
  4. A Zustand store
जवाब देखें

जवाब: A useGetPostsQuery React hook

Hooks are named after the endpoints.

पाठ: createApi and Endpoints

11. What happens when a mutation invalidates a tag a subscribed query provides?

  1. Nothing until the page reloads
  2. The whole store is reset
  3. The mutation is retried
  4. That query refetches automatically
जवाब देखें

जवाब: That query refetches automatically

Tags link mutations to the cached queries they affect.

पाठ: Caching, Tags and Invalidation

12. How do you roll back an optimistic cache patch when the request fails?

  1. Reload the page
  2. Call undo() on the patch result returned by dispatching updateQueryData
  3. Dispatch api.util.resetApiState() always
  4. Throw from the reducer
जवाब देखें

जवाब: Call undo() on the patch result returned by dispatching updateQueryData

The patch result knows how to reverse itself.

पाठ: Optimistic Updates and Polling

Redux Patterns That Scale

13. What shape does createEntityAdapter give a collection?

  1. A nested tree of objects
  2. An ids array plus an entities lookup object
  3. A Map stored in state
  4. A plain array only
जवाब देखें

जवाब: An ids array plus an entities lookup object

Normalised state makes lookups and updates O(1) by ID.

पाठ: Normalising Data with createEntityAdapter

14. When does a createSelector result function run again?

  1. Whenever any component re-renders
  2. On every call
  3. Only once at startup
  4. When one of its input selector results changes by reference
जवाब देखें

जवाब: When one of its input selector results changes by reference

Memoisation is keyed on input results.

पाठ: Memoised Selectors with createSelector

15. In Redux Toolkit 2, how should custom middleware check an action type safely?

  1. Use an action creator's .match(action) or isAction
  2. Cast action to any
  3. Compare action.name
  4. Read action from getState
जवाब देखें

जवाब: Use an action creator's .match(action) or isAction

The action parameter is unknown and must be narrowed.

पाठ: Middleware and Redux DevTools

Zustand Essentials

16. What does set({ items: [] }) do in Zustand?

  1. Deep-merges every nested object
  2. Replaces the whole state with { items: [] }
  3. Shallow-merges items into the existing state
  4. Throws because set needs a function
जवाब देखें

जवाब: Shallow-merges items into the existing state

set merges at the top level unless you pass replace = true.

पाठ: Creating a Store

17. Why wrap (s) => ({ a: s.a, b: s.b }) in useShallow?

  1. Selectors cannot return objects at all
  2. useShallow makes the store persist
  3. The selector returns a new object every call, so it needs shallow comparison
  4. It converts the store to Redux
जवाब देखें

जवाब: The selector returns a new object every call, so it needs shallow comparison

Shallow comparison keeps the previous reference when values are equal.

पाठ: Selectors and Avoiding Re-renders

18. How do you write an async action in Zustand?

  1. As an async function in the store that calls set before and after await
  2. With a required createAsyncThunk import
  3. Only through middleware
  4. By returning a Promise from the selector
जवाब देखें

जवाब: As an async function in the store that calls set before and after await

Actions are plain functions.

पाठ: Async Actions and the Slices Pattern

Zustand in Depth

19. What does the persist option partialize do?

  1. Encrypts state
  2. Splits the store into slices
  3. Compresses state
  4. Chooses which parts of state are saved to storage
जवाब देखें

जवाब: Chooses which parts of state are saved to storage

Only the returned fields are persisted.

पाठ: persist, devtools and immer Middleware

20. How can a non-React module read a Zustand store created with create?

  1. It cannot; Zustand only works in components
  2. Call useStore.getState()
  3. Import the Provider
  4. Dispatch a getState action
जवाब देखें

जवाब: Call useStore.getState()

The hook exposes the vanilla store API.

पाठ: Stores Outside React and with TypeScript

21. Why call setState(initial, true) in beforeEach?

  1. To speed up rendering
  2. To restore a clean store so tests do not leak state into each other
  3. To enable devtools in tests
  4. To persist state between test files
जवाब देखें

जवाब: To restore a clean store so tests do not leak state into each other

Module-level stores keep their state across tests otherwise.

पाठ: Testing Stores

Choosing and Scaling

22. Why is React Context a poor fit for frequently changing global state?

  1. Context values are lost on every render
  2. Context cannot hold objects
  3. Context only works in class components
  4. Every consumer re-renders when the context value changes
जवाब देखें

जवाब: Every consumer re-renders when the context value changes

Context has no built-in selector-based subscriptions.

पाठ: Redux Toolkit vs Zustand vs Context

23. Which tool shows which components rendered during an interaction?

  1. The React DevTools Profiler
  2. The browser Network tab
  3. The TypeScript compiler
  4. npm audit
जवाब देखें

जवाब: The React DevTools Profiler

Profile before optimising.

पाठ: Performance and Re-render Debugging

24. What is a safe first step when migrating legacy Redux to RTK?

  1. Switch to Zustand first
  2. Rewrite every reducer in one pull request
  3. Replace createStore with configureStore while keeping the existing reducers
  4. Remove all middleware
जवाब देखें

जवाब: Replace createStore with configureStore while keeping the existing reducers

configureStore accepts existing reducers, so the app keeps working.

पाठ: Migrating Legacy Redux to Redux Toolkit

25. Which belongs on a state management checklist?

  1. Fetch calls live inside reducers
  2. Every input value lives in the global store
  3. Components select the smallest value they need
  4. Auth tokens are persisted in localStorage by default
जवाब देखें

जवाब: Components select the smallest value they need

Small, stable selections keep re-renders down.

पाठ: A State Management Checklist

← कोर्स पर वापस जाएँ