我需要为该页面加载帖子,因此我将此操作创建者称为:
export const getPosts = () => async (dispatch) => {
try {
const response = await fetch('/api/posts');
const posts = response.json();
dispatch({
type: SET_POSTS,
posts: response.posts
});
} catch(err) {}
};
我应该叫动作类型SET_POSTS
吗?应该调用它GET_POSTS
吗?
我去了,SET_POSTS
因为从技术上讲,该职位已经被提取,剩下要做的就是将这些职位设置为状态。
有关命名动作类型的最佳做法是什么?
我们现在建议将动作类型编写为"domain/eventName"
,而不是"SOME_THING"
。我们还建议将动作建模为“事件”,而不是概念上的“设定者”。
在这种情况下,我建议使用{type: "posts/postsReceived"}
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句