i don't know why when i click on DigitButton the calculator disappeare like there is a bug. I know the problem is on the curerentOperation property side but I actually don't know which problem it is. When i remove the currentOperation and previousOperator in the backticks each digit is rendered.
here is the linkto my Pen
CodePudding user response:
In your reducer you need to get access to previousOperation
using state.previousOperation
const reducer = (state, { type, payload }) => {
switch (type) {
case ACTIONS.ADD_DIGIT:
return {
...state,
previousOperation: `${""}${payload.digit}`,
currentOperation: `${""}${payload.digit}`
};
case ACTIONS.CLEAN:
return {};
case ACTIONS.ADD_OPERATOR:
return {
...state,
// Line: 43
previousOperation: `${state.previousOperation || ""}${payload.operator}`
};
}
};