DEV Community

Matt Crowder
Matt Crowder

Posted on

What's the difference between an action creator and a action?

An action is simply an object that has two things: a type, and a payload.

An action creator is simply a function, that just returns an action.

Why do we care about action creators? I don't think one should care to correct people who don't differentiate between actions and action creators, but it is a good thing to make action creators, because it provides a way to have reusable actions that you can use all throughout your code base.

Also, you can add logic in there that you may not want to have to remember to do each time you use an action.

My favorite example is when you have to create a uniquely generated id.

import shortid from "shortid";

export const addPost = ({ title, body }) => {
    return {
        id: shortid.generate()
Enter fullscreen mode Exit fullscreen mode

What do you like to do with your action creators?

Top comments (0)