Reactjs Redux商店已更新,但不是';t在MapStateTops中反映

Reactjs Redux商店已更新,但不是';t在MapStateTops中反映,reactjs,d3.js,redux,redux-thunk,Reactjs,D3.js,Redux,Redux Thunk,我一直在尝试从一个外汇API中提取数据,但我有点困惑,因为为什么更改没有通过mapStateToProps反映出来 本质上,我试图通过动作创建者调用api。这里是动作创造者 export const fetchTimeData = (currency, date) => { return async (dispatch) => { const res = await axios.get(`http://api.fixer.io/${date}?base=${curre

我一直在尝试从一个外汇API中提取数据,但我有点困惑,因为为什么更改没有通过mapStateToProps反映出来

本质上,我试图通过动作创建者调用api。这里是动作创造者

export const fetchTimeData = (currency, date) => {
    return async (dispatch) => {
    const res = await axios.get(`http://api.fixer.io/${date}?base=${currency}`);

    const temp  = res.data.rates;
    var arr = Object.keys(temp).map(function (key) { 
      return (
          temp[key]
      ); 
    });

    var arr2 = Object.keys(temp).map(function (key) { 
      return (
          key
      ); 
    });

    var empty = [];

    for(var i = 0; i < arr.length; i++){
      empty[i] = {title: arr2[i], value: arr[i]};
    }

    _.remove(empty, {title: 'IDR'});
    _.remove(empty, {title: 'KRW'});
    _.remove(empty, {title: 'HUF'});

    empty.sort((a, b) => {
        var titleA = a.title.toLowerCase()
        var titleB = b.title.toLowerCase()
        if (titleA < titleB) //sort string ascending
            return -1 
        if (titleA > titleB)
            return 1
        return 0 //default return value (no sorting)
    })

    dispatch({type: FETCH_TIME_DATA, payload: empty});
  }
};
我已经尝试过用redux logger进行调试,我看到操作被正确触发。但是,我仍然得到一个空数组

在我的另一个类似的action creator中,我从api和mapeStateTo道具中获取数据没有问题


我觉得在理解redux在组件生命周期中是如何更新的过程中,我遗漏了一个关键部分,但我不确定具体是什么。如果您想更仔细地了解一下,回购协议就在这里。

您是否在组合减速器中添加了减速器?

您是否在组合减速器中添加了减速器?

我没有看到您在组件中的任何位置使用currencyTime和saveTime,那么您如何知道它没有反映出来?您是否正在组件中的某个位置执行console.log以查看它是否已更新?@Yeo Wand:您找到答案了吗?如果不尽快让我知道,我会帮助你的!我没有看到您在组件中的任何地方使用currencyTime和saveTime,那么您如何知道它没有反映出来?您是否正在组件中的某个位置执行console.log以查看它是否已更新?@Yeo Wand:您找到答案了吗?如果不尽快让我知道,我会帮助你的!组件的
MapStateTrops
中的数据很好,但是在渲染函数中看不到对任何道具的引用。您可以分享您在MapStateTrops函数中编写的代码吗?并检查是否已将MapStateTops传递给连接,即导出默认连接(MapStateTops,{})(ComponentName)自行查找P.S.这不是我的代码我的联合收割机还原器是从“redux”导入的{combineReducers};从“/dataReducer”导入dataReducer;导出默认合并还原程序({data:dataReducer});它是已连接的导出默认连接(MapStateTops,actions)(DateChart);如果我在组件中添加一个{console.log(this.props.saveTime)},我会得到一个空数组。组件的
MapStateTrops
中的数据很好,但是在渲染函数中看不到对任何props的引用。你能分享你在MapStateTrops函数中编写的代码吗?并检查是否已将MapStateTops传递给连接,即导出默认连接(MapStateTops,{})(ComponentName)自行查找P.S.这不是我的代码我的联合收割机还原器是从“redux”导入的{combineReducers};从“/dataReducer”导入dataReducer;导出默认合并还原程序({data:dataReducer});它是已连接的导出默认连接(MapStateTops,actions)(DateChart);如果我在组件中添加一个{console.log(this.props.saveTime)},我会得到一个空数组。
componentWillMount() {
    this.calculateDays();
}

calculateDays() {
    var currentDate = moment();
    var hold = enumerateDays('2017-8-10', currentDate);

    var days = [];
    var firstDay = hold[0];
    var currencies;

    days = hold.map((date) => {

        var inBetween = calculateBetween(firstDay, date);
        this.props.fetchTimeData(this.props.base, date);

        console.log("this is tempData", this.props.saveTime)

        return(
            {
                currencies: 'test',
                date: date,
                days: inBetween
            }
        )
    })

}

render(){

    const margins = { top: 50, right: 20, bottom: 100, left: 60 };
    const svgDimensions = { width: 1400, height: 800 };

    var data = [
      {
          "age": 39,
          "index": 0
      },
      {
          "age": 38,
          "index": 1
      },
      {
          "age": 34,
          "index": 2
      },
      {
          "age": 12,
          "index": 3
      }
  ];

  //for color, pass the array of colors to the redux store then pop off from the beginning into chartSeries

  var chartSeries = [
      {
        field: 'age',
        name: 'USD',
        color: '#ff7f0e',
        style: {
          "stroke-width": 2,
          "stroke-opacity": .2,
          "fill-opacity": .2
        }
      }
    ]

    //iterate over a list of years and calculate days from using moment
    //the data will have years, but the function down here will change it
    //set the very first index date as the "from" date in moment.js
    var x = function(d) {
      return d.index;
    }

    return(
        <div>
            <LineChart
                margins= {margins}
                width={svgDimensions.width}
                height={svgDimensions.height}
                data= {data} 
                chartSeries= {chartSeries} 
                x= {x}
            />
            {console.log(this.props.saveTime)}
        </div>
    );
}

function mapStateToProps(state) {
    return {
        saveTime: state.data.currencyTime
    };
}

export default connect(mapStateToProps, actions)(DateChart);
const INITIAL_STATE = {
    currency: fakeData,
    currencyTime: []
}

export default function(state = INITIAL_STATE, action) {
    switch (action.type){
        case FETCH_DATA:
            return {...state, currency: action.payload};
        case FETCH_TIME_DATA:
            return {...state, currencyTime: action.payload};
        default:
           return state;
   }
}