Reducer日志'已删除'但它仍存在于firestore数据库中......?

问题描述 投票:2回答:1

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

客户端列表:

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,登录控制台没有错误。

reactjs firebase redux google-cloud-firestore action
1个回答
0
投票

试试这个。 .doc(id)因为id必须是字符串。

我认为你不需要qazxsw poi里面的qazxsw poi。

/

doc
© www.soinside.com 2019 - 2024. All rights reserved.