@Quintis

Как написать простой счетчик на redux?

Доброго времени суток , нужно написать простенький счетчик что б пройти задание на FCC - https://www.freecodecamp.org/learn/front-end-libra...
Написал код но он не считает , кто может сказать где ошибка ?
const INCREMENT ='INCREMENT' ; // define a constant for increment action types
const DECREMENT = 'DECREMENT'; // define a constant for decrement action types

const counterReducer = (state=0,action)=>{
      switch(action.type) {
    case 'INCREMENT':
      return state+1;
      break;
    case 'DECREMENT':
      return state-1;
          break;
    default:
      return state;
  }
}; // define the counter reducer which will increment or decrement the state based on the action it receives

const incAction = ()=>{
    return {
        type:INCREMENT
    }
}; // define an action creator for incrementing

const decAction = ()=>{
    return {
        type:DECREMENT
    }
}; // define an action creator for decrementing

const store = Redux.createStore(counterReducer); // define the Redux store here, passing in your reducers
console.log(store.dispatch(incAction()));
  • Вопрос задан
  • 554 просмотра
Пригласить эксперта
Ответы на вопрос 1
Lynn
@Lynn
nginx, js, css
Ваш редюсер всегда возвращает 0.

https://developer.mozilla.org/en/docs/Web/JavaScri...

If used postfix, with operator after operand (for example, x++), then it increments and returns the value before incrementing.
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы