Reputation: 466
I am new in redux library of react This is my code
// action creator
export function updateCategories(payload) {
return { type: UPDATE_CATEGORY, payload };
}
// dispatch action creator
dispatch(updateCategories({ list: data }));
But instead if I do like :
dispatch({ type: UPDATE_CATEGORY, payload });
so what is problem if I write action directly in dispatch without returning from function?
Upvotes: 0
Views: 295
Reputation: 198
It helps in code re-usability. You can go through this link for more Info
Upvotes: 0
Reputation: 9063
Technically it's fine, you can dispatch
straight from the component, but there's advantages of having actions creators, e.g.
redux-thunk
). It's better to have a single action creator where that's all defined that you can reuse throughout your application, rather than copy pasting that logic all over the placeUpvotes: 2