首页 > 解决方案 > 在 redux-saga 中获取数据后如何在组件中调用渲染?

问题描述

我正在尝试从 redux saga 获取新数据,但我无法得到它。新日期不会在我的组件中刷新,但在 redux 中它们会更新。

sagas.js

function* getApiData(action) {
  try {
    // do api call
    const data = yield call(fetchData);
    yield put(receiveApiData(data));
  } catch (e) {
    console.log(e);
  }
}

零件

  render() {
    const  results  = this.props.data;
    if (results.lenght) { // I'm trying to check for storage length, but this does not work
      return (
        results.map((item, index) => {
          <div key={index}>
          <h1>
            {item.dstOffset}
          </h1>
          <h1>
            {item.rawOffset}
          </h1>
          <h1>
            {item.timeZoneId}
          </h1>
        </div>} )
      )
   }
   else {
     return (
       <div>loading</div>
     )
   }
  }
}

const mapStateToProps = state => ({ data: state.data });

标签: javascriptreactjsredux-saga

解决方案


推荐阅读