首页 > 解决方案 > Firestore在React Application中通过Redux-Saga添加数据时添加重复记录

问题描述

我正在尝试在反应应用程序中使用 redux-saga 在 Firestore 中添加记录。我可以添加数据,但它会添加两次相同的数据。但是在页面刷新时,重复数据会自动删除。你能看看下面的方法为什么会这样吗?

export function* onAddContactAsync({ payload: contact }) {
  try {
    yield delay(500)
    yield new Promise((resolve) => {
      db.collection("contacts").doc().set(contact, resolve);
    });
    yield put(addContactSuccess());
  } catch (error) {
    yield put(addContactFail());
  }
}
export function* onAddContact() {
  yield takeLatest(types.ADD_CONTACT_START, onAddContactAsync);
}


const combineSagas = [fork(onAddContact)];

export function* contactsSagas() {
  yield all([...combineSagas]);
}

标签: reactjsfirebaseredux-saga

解决方案


推荐阅读