您要请求功能还是报告 bug ?
错误
当前行为是什么? 加载页面后,我得到的保护数据如下所示:
但是,删除项目后,将嵌入冗余todayFeed
。对于每个删除的项目,将再次添加todayFeed
字段(此字段不是在Firestore中创建的,仅在刷新页面之前存在于redux存储中)。商店更新后,实际商品数组的长度是相同的,并且看起来好像商品没有被删除(即使商品已从firestore集合中删除,并且刷新后的页面数据也类似于第一个屏幕截图)但与预期相比,数组中的项减少了一个)
用户调度操作(redux)以删除Firestore集合中的项目
this.props.deleteItem(item);
在那之后,我在中间件中使用redux-thunk
并使用额外的参数(getFirebase
,getFirestore
)来访问动作创建者中的firebase和firestore。
let store = createStore(reducer,
compose(
applyMiddleware(thunk.withExtraArgument({ getFirebase, getFirestore })),
reduxFirestore(firebaseConfig),
reactReduxFirebase(firebaseConfig, { useFirestoreForProfile: true, userProfile: 'users', attachAuthIsReady: true })
)
);
动作创作者:
import { getFirestore } from "redux-firestore";
export const deleteItem = itemToDelete => {
return (dispatch, getState, { getFirebase, getFirestore }) => {
const firestore = getFirestore();
const authorId = getState().firebase.auth.uid;
const userRef = firestore.collection("users").doc(authorId);
userRef
.collection("todayFeed")
.doc(itemToDelete.uid)
.delete()
.then(res => {
dispatch({ type: "CHANGE_ITEM_STATE_SUCCESS", res });
})
.catch(err => {
dispatch({ type: "CHANGE_ITEM_STATE_ERROR", err });
});
};
};
我使用react-redux-firebase
来获取视图文件中的数据。
let mapStateToProps = state => {
return {
auth: state.firebase.auth,
items:
state.firestore.ordered.users &&
state.firestore.ordered.users.length &&
state.firestore.ordered.users[0].todayFeed
};
};
export default compose(
connect(mapStateToProps),
firestoreConnect(props => {
return [
{
collection: "users",
doc: props.auth.uid,
subcollections: [
{ collection: "todayFeed", orderBy: ["pubDate", "desc"] }
]
}
];
})
)(Dashboard);
预期的行为是什么?
删除项目后,以预期的格式(不嵌入多余的todayFeed
字段)获取数据。
哪个版本的依赖项以及哪个浏览器和操作系统受此问题影响?这在以前的版本或设置中有效吗?
操作系统:Windows 10
依赖项:
"dependencies": {
"cors": "^2.8.5",
"firebase": "^5.5.5",
"googleapis": "^42.0.0",
"moment": "^2.24.0",
"react": "^16.9.0",
"react-dom": "^16.9.0",
"react-firebaseui": "^3.1.2",
"react-redux": "^5.0.7",
"react-redux-firebase": "^2.3.0",
"react-router-dom": "^4.3.1",
"react-scripts": "2.0.5",
"react-spring": "^5.1.3",
"react-with-gesture": "^1.0.10",
"redux": "^4.0.1",
"redux-firestore": "^0.5.8",
"redux-thunk": "^2.3.0",
"scriptjs": "^2.5.9",
"styled-components": "^3.2.6"
},