Reducer日志已“删除”,但仍存在于Firestore数据库中...? [英] Reducer logs 'deleted' but it still exists in firestore database...?

查看:79
本文介绍了Reducer日志已“删除”,但仍存在于Firestore数据库中...?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

'id'通过操作和reducer发送并注销'deleted',但实际上并未从firestore数据库中删除...

'id' gets sent through action and reducer and logs out 'deleted' but doesn't actually delete from firestore database...

clientlist:

clientlist:

class Clients extends Component {

  handleClick = (id) => {
    // e.preventDefault();
    this.props.deleteClient(id)
  }

  render() {
    const {clientList} = this.props
    return (
      <div className="container mt-5 text-center">
        <h2>Here Are Your List of Clients...</h2>
        {clientList && clientList.map(client => {
          return(
            <div key={client.id}>
              <div className="my-2">
                Client Name: {client.name} | Client Price: ${client.price}
                <button className="ml-2" onClick={() => {this.handleClick(client.id)}}>x</button>
              </div>      
            </div>

          )
        })}
        <AddClient/>
      </div>
    )
  }
}

const mapStateToProps = (state) => {
  return {
    clientList : state.firestore.ordered.clientList,
  }
}

const mapDispatchToProps = (dispatch) => {
  return{
    deleteClient : (id) => dispatch(deleteClient(id)) 
  }
}

export default compose(
  connect(mapStateToProps, mapDispatchToProps),
  firestoreConnect([
    {collection: 'clientList', orderBy: 'name'},
  ])
)(Clients)

操作:

export const deleteClient = (id) => {
    return(dispatch, getState, {getFirestore, getFirebase}) => {
        const firestore = getFirestore();
        firestore.collection("clientList").doc(id).delete().then(() => {
            dispatch({type: 'DELETE CLIENT'})
        }).catch((err) => {
            dispatch({type: 'DELETE CLIENT ERROR', err})
        });

    }     
}

让我知道您是否需要其他代码或信息。 ps,登录到控制台没有错误。

let me know if you need any other code or information. ps, there is no error logging out into the console.

推荐答案

尝试一下。 .doc(id),因为id必须是字符串。

Try this. .doc(id) because id has to be string.

我认为您不需要 / doc 内。

检查api。

export const deleteClient = (id) => {
    console.log(id);
    return(dispatch, getState, {getFirestore, getFirebase}) => {
        const firestore = getFirestore();
        firestore.collection('clientList').doc(id).delete().then(() =>{
            dispatch({type: 'DELETE CLIENT'})
        }).catch((err) => {
            dispatch({type: 'DELETE CLIENT ERROR', err})
        })
    }     
}

这篇关于Reducer日志已“删除”,但仍存在于Firestore数据库中...?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆