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

Actions

Actions are simple objects containing information that sends data from your app over to the app's store. All the logic that your app handles will pass through the action - your store never receives any data from sources that aren't actions.

An action requires a type property, which defines the type of user action that has occurred. Types of actions are represented in a stringified form. They can be hardcoded into the object itself or passed in as a constant. For example:

export function addTask(taskName) { 
  return { 
    type: 'ADD_TASK', 
    taskName: taskName 
  } 
} 
 
// With constants 
 
const ADD_TASK = 'ADD_TASK'; 
 
export function addTask(taskName) { 
  return { 
    type: ADD_TASK, 
    taskName: taskName 
  } 
} 

These functions will be made available as props ...

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