I encountered the following code and I’m trying to make sense of it. When I substitute my simplified version of the code in question, the application doesn’t work.
The original code is:
const state = {count: 0}
const reducers = {
add: (state) => ({count: state.count + 1}),
sub: (state) => ({count: state.count - 1}),
}
My dumbed-down version is:
const myReducersAsAnObject = {
add : function (state) {
return count = state.count + 1
},
sub: function (state){
return count = state.count - 1
}
}
Where am I going wrong?