Answer the question
In order to leave comments, you need to log in
How to get rid of code duplication in redux?
Hello!
I write several reducers using the redux toolkit like this:
const initialState = {
loading: false,
data: [],
errors: {},
};
const keyNameSlice = createSlice({
name: "keyName",
initialState,
reducers: {
setLoader: (state) => {
state.loading = true;
state.errors = initialState.errors;
},
setData: (state, action) => {
const { payload } = action;
state.loading = false;
state.data = payload;
},
setError: (state, action) => {
const { payload } = action;
state.loading = false;
state.errors = payload;
},
},
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question