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

Creating actions

Let's create some actions that will help us with our application. In the Tasks app, we had functionality for the following actions:

  • Fetching tasks from AsyncStorage
  • Creating a new task
  • Editing a task's name
  • Marking/unmarking a task as complete
  • Showing/hiding the expandable component
  • Saving changes to a task
  • Clearing changes to a task
  • Adding a due date
  • Removing a due date

Here's an example of how an action for editing a task's name can look:

export function editTaskName (title, index) { 
  return { 
    type: 'EDIT_TASK_NAME', 
    title: title, 
    index: index 
  } 
}; 

When naming an action, we want to correlate the type of action with exactly what has happened as a result of a user interaction. In this case, the user edited the task name. ...

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