State Management · Middle · Question 54 of 75
How do you skip a thunk if the data is already loaded or loading?
createAsyncThunk("users/fetch", fetchUsers, {
condition: (_, { getState }) => getState().users.status === "idle",
});- ✓Correct answer: Use the
conditionoption, which can cancel the thunk before it starts - 2Throw an error inside the payload creator
- 3Check it in the reducer
Explanation
When condition returns false, no actions are dispatched. RTK Query handles such deduplication automatically.