How can I dispatch an action from inside the merge
method on a query?
#3463
-
Hello, I'll use sliceFoo and sliceBar to distinguish between where I want to update. The action on sliceFoo also saves the value to local storage.
But with this, I'm not having success. Is this possible through the Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
RTKQ is built on top of createAsyncThunk, and the lifecycle actions are dispatched as usual. For convenience, matchers are attached to each endpoint. As a result, you can respond to an endpoint fulfilling from another slice using extraReducers: extraReducers: (builder) => {
builder.addMatcher(
api.endpoints.getFoo.matchFulfilled,
(state, action) => {
const { payload } = action;
}
)
} this seems a much cleaner solution than dispatching from merge. |
Beta Was this translation helpful? Give feedback.
yeah, exactly
your slice's case reducers are exposed as slice.caseReducers, so you could do