Este código no funciona dando el error 'currentOperand' no está definido
function reducer(state, action) { switch(action.type) { case 'choose_operation': currentOperand = 0; return {...state, {/*operation*/}}; } } const [{ currentOperand, previousOperand, operation }, dispatch] = useReducer(reducer, {}); dispatch({type: 'choose_operation'})Tampoco este que muestra el mismo error 'currentOperand' no está definido
function reducer(state, action) { switch(action.type) { case 'choose_operation': state[0] = 0; // state.currentOperand = 0; return {...state, {/*operation*/}}; } } const [[ currentOperand, previousOperand, operation ], dispatch] = useReducer(reducer, []); dispatch({type: 'choose_operation'})Este está funcionando pero tengo que especificar la matriz en cada retorno
function reducer([ currentOperand, previousOperand, operation ], action) { switch(action.type) { case 'choose_operation': currentOperand = 0; return [ currentOperand, previousOperand, operation ]; } } const [[ currentOperand, previousOperand, operation ], dispatch] = useReducer(reducer, [",","]); dispatch({type: 'choose_operation'})