DEV Community

Matt Crowder
Matt Crowder

Posted on

5 2

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 {
        title,
        body,
        id: shortid.generate()
    };
};
Enter fullscreen mode Exit fullscreen mode

What do you like to do with your action creators?

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay