Migrating Redux reducers to Rematch reducers
Rematch models contain a state
property, a reducers
property, and an effects
property. We can use state
to add the initial state, and inside reducers
, we can move our Redux reducers directly to the reducers' model
property:
const INITAL_STATE = { Â Â todos: [] } function reducer(state = INITAL_STATE, action) { Â Â switch(action.type) { Â Â Â Â case "ADD_TODO": { Â Â Â Â Â Â const newTodo = { Â Â Â Â Â Â Â Â id: Date.now(), Â Â Â Â Â Â Â Â title: action.title, Â Â Â Â Â Â Â Â completed: false, Â Â Â Â Â Â } Â Â Â Â Â Â return { Â Â Â Â Â Â Â Â ...state, Â Â Â Â Â Â Â Â todos: [...state.todos, newTodo] Â Â Â Â Â Â } Â Â Â Â ...