# Action

Defines an action against your model

# API

Action<
  Model extends object = {}, 
  Payload = void
>
  • Model

    The model against which the action is being defined. You need to provide this so that the state that will be provided to your action is correctly typed.

  • Payload

    The type of the payload that the action will receive. You can omit this if you do not expect the action to receive any payload.

# Example

import { Action, action } from 'easy-peasy';

interface TodosModel {
  todos: string[];
  addTodo: Action<TodosModel, string>;
}

const todosModel: TodosModel = {
  todos: [],
  addTodo: action((state, payload) => {
    state.todos.push(payload);
  })
}