# Redux Tutorial: Define Action Types

Step 1: Create redux-todolist/src/redux/actions/actionTypes/todos.js

Let us start by creating a new action type file: redux-todolist/src/redux/actions/actionTypes/todos.js. Paste the following code into the newly created file:


module.exports = {
  ALL_TODOS: 'ALL_TODOS',
  EDIT_TODO: 'EDIT_TODO',
  CREATE_TODO: 'CREATE_TODO',
  REMOVE_TODO: 'REMOVE_TODO',
  SINGLE_TODO: 'SINGLE_TODO',
};

Actions in Redux must have a type property that indicates the type of action being performed. We define these action types constants in this file so it can be reused throughout the project. 5 action types are defined:

  • ALL_TODOS type indicates that the data fetched has all todo items.
  • EDIT_TODO type indicates that the data dispatched mutates the particular todo item.
  • CREATE_TODO type indicates that the data dispatched is used to create a new Todo item.
  • REMOVE_TODO type indicates that the data dispatched is used for removing a todo item from the todos collection.
  • SINGLE_TODO type indicates that the data fetched is for a single todo item.

Step 2: Import: redux-todolist/src/redux/actions/actionTypes/index.js

Open redux-todolist/src/redux/actions/actionTypes/index.js and import the action type file defined above. Your index.js file should look something like this:


import todos from './todos';

module.exports = {
  ...todos
};

Now that we have defined our action type file and imported it accordingly let us now create actions that query/mutate the todos collection via the GraphQL service. This is described in the next section.