Raw RTK With Extra Reducers
extraReducers
দিয়ে অন্য slice এর actions এ response করা যায়। এটি cross-slice communication এর জন্য ব্যবহৃত হয়।
কোড
Slice
dynamicCounterSlice.js
const { createSlice } = require("@reduxjs/toolkit");
const {
counterActions,
} = require("../../../../tutorial-14/rtk/features/counter/counterSlice");
// initial state
const initialState = {
count: 20,
};
const dynamicCounterSlice = createSlice({
name: "dynamicCounter",
initialState,
reducers: {
increment: (state, action) => {
state.count += action.payload;
},
decrement: (state, action) => {
state.count -= action.payload;
},
},
extraReducers: (builder) => {
builder.addCase(counterActions.increment, (state, action) => {
state.count += 1;
});
},
});
module.exports = dynamicCounterSlice.reducer;
module.exports.dynamicCounterActions = dynamicCounterSlice.actions;
extraReducers
এ অন্য slice এর actions import করে ব্যবহার করতে হয়। এখানে counterActions.increment
এ response করছে। Last updated on