如何从调度中获得价值?

问题描述

如何从Createtobaccoprofile派遣中获取烟草ID?

const addToBarProfile = (data,dispatch) => new Promise((resolve,reject) => {
  var somedata = dispatch(Createtobaccoprofile({
    data: JSON.stringify(data)
  }));
  //I need id of this request to send new request
  debugger;
  resolve();
});

addToBarProfile(data,dispatch).then(x => {
  debugger;
  AttachTobaccoToBar(data._id);
});

解决方法

我认为redux调度是同步的,因此您可以这样做,但是您确定 CreateTobaccoProfile

    CreateTobaccoProfile({
            data: JSON.stringify(data),}) 

返回值?操作不应返回值,而只是启动状态更改

   const addToBarProfile = (data,dispatch) =>
      new Promise((resolve,reject) => {
        var somedata = dispatch(
          CreateTobaccoProfile({
            data: JSON.stringify(data),})
        );
        //I need id of this request to send new request
        debugger;
        if (!somedata) return reject(new Error("no data found !"));
        resolve(somedata);
      });

addToBarProfile(data,dispatch).then((somedata) => {
  debugger;
  AttachTobaccoToBar(somedata._id);
});