使用reselect
时,在选择器中执行检查是否正常?
const getComments = state => state.entities.comments;
const getCommentIds = (state, props) => {
const id = props.match.params.post;
const comments = state.pagination.comments[id];
return (comments && !comments.isFetching) ? comments.ids : []; // this line
}
export const getCommentsForPost = createSelector(
[ getComments, getCommentIds ], (comments, ids) => {
return ids.map(id => comments[id]);
}
)
答案 0 :(得分:3)
选择器是用于访问商店数据的其他应用的公共界面。在我的书中进行检查以使您的消费应用程序代码更好。
对于你上面的具体情况,我可能只是将isFetching布尔值传递给组件,并让它处理如何处理它在获取时显示的内容而不是,但是如果你有什么是完全正常的,如果它得到了你正在寻找的行为。