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",
});

Explanation

When condition returns false, no actions are dispatched. RTK Query handles such deduplication automatically.

Further reading

Problem with a question

State Management · Middle · question 54

Test yourself

Take the State Management · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz