O'Reilly logo

React Native By Example by Richard Kho

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Modifying our reducers

We need to modify our reducers file so that it does the following:

  • Adds the currentIndex property to its defaultState object
  • Sets the index of a task when it is added to our state tree
  • Increases the currentIndex property of our state tree by one when adding a new task
  • Contains a switch case for the SET_LIST_OF_TASKS_AND_INDEX action, setting the currentIndex and listOfTasks properties of our state tree to the results of our getListOfTasksAndIndex thunk
// TasksRedux/app/reducers/index.js 

const defaultState = { 
  currentIndex: undefined, 
  ... 
} 
... 
const singleTask = (state = {}, action) => { 
  switch(action.type) { 
    case 'ADD_TASK': 
      return { 
        ... 
        index: action.index, 
      } 
    ... 
  } 
} 

The ADD_TASK case in the singleTask sub-reducer ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required