Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs React-Redux表单-当我触发更新操作并调用另一个函数的调度时,我的列表不会得到更新_Reactjs_React Redux_Redux Form - Fatal编程技术网

Reactjs React-Redux表单-当我触发更新操作并调用另一个函数的调度时,我的列表不会得到更新

Reactjs React-Redux表单-当我触发更新操作并调用另一个函数的调度时,我的列表不会得到更新,reactjs,react-redux,redux-form,Reactjs,React Redux,Redux Form,我有一个redux表单中的submit函数,它应该在用户点击createcustomer或updatecustomer时更新客户列表 当用户单击CreateCustomer时,它将创建客户并触发this.props.dispatchfetchCustomers;获取更新的列表。但是,当我单击Update Customer时,它不会获取更新的数据。我做错了什么 以下是我在我的组件中的功能: submit(formProps) { const customer = {

我有一个redux表单中的submit函数,它应该在用户点击createcustomer或updatecustomer时更新客户列表

当用户单击CreateCustomer时,它将创建客户并触发this.props.dispatchfetchCustomers;获取更新的列表。但是,当我单击Update Customer时,它不会获取更新的数据。我做错了什么

以下是我在我的组件中的功能:

submit(formProps) {

      const customer = {
        name: formProps.get('name'),
        director: formProps.get('director'),
        manager: formProps.get('manager'),
        supervisor: formProps.get('supervisor'),
        contact: {
          name: formProps.get('contact').get('name'),
          phone_number: formProps.get('contact').get('phone_number'),
          email: formProps.get('contact').get('email'),
        },
      };

      // Are we editing?
      if(this.state.isEditingCustomer) {
        customer['_id'] = this.state.customer._id;
        this.props.dispatch(updateCustomer(customer));
      } else {
        // Dispatch action to convert the request to a work order
        this.props.dispatch(createCustomer(customer));
      }

      // Get the users
      this.props.dispatch(fetchCustomers());

      // Close the modal
      this.handleClose();
    }
以下是操作创建者:

export function updateCustomer(customer) {
  return {
    type: UPDATE_CUSTOMER,
    payload: customer,
    url: `/customer/${customer._id}`,
    success: UPDATE_CUSTOMER_SUCCESS,
  };
}
export function fetchCustomers() {
  return {
    type: FETCH_CUSTOMERS,
    payload: null,
    url: '/customers/',
    success: FETCH_CUSTOMERS_SUCCESS,
  };
}
我使用的是sagas,下面是我的updateCustomerFlow Saga:

以下是我的fetchCustomers操作创建者:

export function updateCustomer(customer) {
  return {
    type: UPDATE_CUSTOMER,
    payload: customer,
    url: `/customer/${customer._id}`,
    success: UPDATE_CUSTOMER_SUCCESS,
  };
}
export function fetchCustomers() {
  return {
    type: FETCH_CUSTOMERS,
    payload: null,
    url: '/customers/',
    success: FETCH_CUSTOMERS_SUCCESS,
  };
}
还有我的故事:

export function* fetchCustomersFlow() {
  while (true) { // eslint-disable-line no-constant-condition
    const request = yield take(FETCH_CUSTOMERS);
    const promise = yield call(getData1, true, request.url, request.payload);
    if (promise.status === 200) {
      yield put({ type: request.success, payload: promise.data.customers });
    }
  }
}

抱歉,fetchCustomers操作创建者在哪里?updateCustomer和createCustomer是否已经开始工作了?嘿,谢谢你的回复。我刚刚为fetchCustomers添加了action creator。updateCustomer和createCustomer都可以工作,但无论出于什么原因,当我运行updateCustomer时,fetchCustomers似乎无法从数据库中获取最新的结果。也许有竞争条件?据我所知,在你给fetchCustomers打电话之前,你的updateCustomers不会解决问题。啊,我明白了。我已经读到,你需要使用像redux think这样的东西来处理这些类型的比赛条件。我继承了这个项目,我相信既然我们使用了sagas和reducer,这和不一定需要redux thunk有关?是这样吗?