Simple Redux Flow

by Lucas Silva

JavaScript

// **Action
const increment = {type: 'INCREMENT'}
const decrement = {type: 'DECREMENT'}

// **Reducer
const reducer = (state = {count: 0}, action) => {
  switch (action.type) {
    case 'INCREMENT':
      return { count: state.count + 1 }
    case 'DECREMENT':
      return { count: state.count - 1 }
    default:
      return state
  }
}

// **Store
const store = Redux.createStore(reducer)

// **Logger
function log() {
  console.log('Count: ', store.getState().count)
}