Duck

An example of /store/redux/app.js following re-duck style

Define `createReducer` helper

const createReducer = (initialState = {}, handlers = {}) => (state, action) => {
  const nextState = produce(state, draft => {
    if (handlers[action.type]) {
      return handlers[action.type](draft, action)
    }
  })

  return nextState
}
circle-info

produce is a function of immerarrow-up-right

Declare initial state

const initialState = {
  locale: 'en',
  theme: 'light',
}

Declare action types

circle-info

prefix app_name/domain_namespace for separating your action from 3rd parties actions such as connected-react-routerarrow-up-right, redux-sagaarrow-up-right when working with redux devtools

Declare action creators

Declare reducer

Declare selectors

circle-info

createSelector is a function of reselectarrow-up-right

Last updated