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()
};
};
What do you like to do with your action creators?
Top comments (0)