I have not found a good answer anywhere, and this seems like a meaningless agreement. In many tutorials and documentation, Redux actions are defined as follows:
{
type: "ACTION_NAME",
payload: {
foo: 123,
bar: 456,
}
}
What is the point of the object payload
? Why not just write this:
{
type: "ACTION_NAME",
foo: 123,
bar: 456,
}
I use Flow, and I like to define all my types of actions as a union, without nested payloads:
type Action = {
type: 'ACTION_NAME',
foo: number,
bar: number,
} | {
type: 'ANOTHER_ACTION',
someData: string,
} | {
type: 'ONE_MORE_ACTION',
moreData: boolean,
}
I don’t need to type payload
so many times, and I get autocomplete and type checking for all my actions, so I'm not sure what I am missing.
Am I missing some of the benefits of not putting all my data inside an object payload
?