Repozytorium Web Developera

React Redux

Useful links

Learning path about Redux/Flux:

  1. Getting Started with Redux: An Intro
  2. Egghead Getting Started with Redux + code/notes
  3. Why use Redux over Facebook Flux?

Redux parts

  • action
  • reducer
  • store
  • view

Action


export function submit (email, name) {
  return {
    type: SUBMIT,
    payload: { email, name }
  }
}
This exemplary action has its unique type, which is defined above. Then other parameters are being passed, and moved further to the reducer when the action is called.

Reduceer


const initialState = {
  isLoading: false,
  isSent: false
}

function simpleReducer (state = initialState, action) {
  switch (action.type) {
    case SUBMIT:
      return Object.assign({}, state, {
        isLoading: true
      })
    case SUBMIT_SUCCESS:
      return Object.assign({}, state, {
        isLoading: false,
        isSent: true
      })
    default:
      return state
  }
}

Bibliography