I am new to redux and react, and I read in Dan Abrahamov's post(https://stackoverflow.com/a/35675304/8643584) that reducers should be pure and affect as little as possible, I want to implement radio button kind of logic, and it looks to me logical to implement this kind of logic inside a reducer, is it acceptable?
I right now implemented the logic, that changes the state for 3 variables at one reducer action, other way I can think of, is making reducers to change 1 value at time, then subscribing for changes, and then within the subscription calling the other 2 reducers to change their value accordingly.
my current logic:
const initialState = {
toggleCreate: false
toggleUpdate: false,
toggleDelete: false,
};
const reductionReducer = (state = initialState, action) =>{
switch (action.type) {
case "CRUDBAR_CREATE":
return {
toggleCreate: !state.toggleCreate,
toggleUpdate: false,
toggleDelete: false,
};
case "CRUDBAR_UPDATE":
return {
toggleCreate: false,
toggleUpdate: !state.toggleUpdate,
toggleDelete: false,
};
case "CRUDBAR_DELETE":
return {
toggleCreate: false,
toggleUpdate: false,
toggleDelete: !state.toggleDelete,
};
default:
return state;
}
};
export default categoryReducer;
the other way, which I suspect might be the acceptable one:
const initialState = {
toggleCreate: false
toggleUpdate: false,
toggleDelete: false,
};
const reductionReducer = (state = initialState, action) =>{
switch (action.type) {
case "CRUDBAR_CREATE":
return {
toggleCreate: !state.toggleCreate,
toggleUpdate: state.toggleUpdate,
toggleDelete: state.toggleDelete,
};
case "CRUDBAR_UPDATE":
return {
toggleCreate: state.toggleCreate,
toggleUpdate: !state.toggleUpdate,
toggleDelete: state.toggleDelete,
};
case "CRUDBAR_DELETE":
return {
toggleCreate: state.toggleCreate,
toggleUpdate: state.toggleUpdate,
toggleDelete: !state.toggleDelete,
};
default:
return state;
}
};
export default categoryReducer;
I expect other developers to be able to contribute to my app without falling into holes, they never expected to. So I ask the more experienced developers for insight, thank you.