Reactjs 无法在antd表上显示API中的JSON数据

Reactjs 无法在antd表上显示API中的JSON数据,reactjs,redux-saga,antd,Reactjs,Redux Saga,Antd,我的父组件是: constructor(){ super(); this.state = {data: []} } componentWillMount(){ this.props.getData(); //makes api call this.setState({data: this.props.data}); //get data stored in the store } render(){ const columns ={ //columns here} ret

我的父组件是:

constructor(){
  super();
  this.state = {data: []}
}
componentWillMount(){
  this.props.getData(); //makes api call
  this.setState({data: this.props.data}); //get data stored in the store
}
render(){
  const columns ={ //columns here}
  return(
    <Tables
      dataSource = {this.state.data}
      columns = {this.columns}
    />
  )
}

const mapStateToProps = state => ({
  data: state.data,
})
const mapDispatchToProps = dispatch => ({
  getData: () => dispatch(getData()),
})
//行动

export const updateData = data => ({
  type: UPDATE_DATA,
  data
});
//还原剂

export const INITIAL_STATE = Immutable({});
export const updateData = (state, action) => {
  console.log('reducers', action.data);
  return { ...state, ...action.data };
};

const ACTION_HANDLERS = {
  [UPDATE_DATA]: updateData,
};

export default createReducer(INITIAL_STATE, ACTION_HANDLERS);
我不知道在设置状态时我做错了什么。我似乎找不出错误

请帮助我

this.setState({data:this.props.data})//获取存储在存储中的数据

目前还没有数据。如果确实要设置状态以使用道具数据,则需要在
组件willreceiveprops(nextrops)
生命周期函数中更新状态,而不是在
组件didmount()

分析此函数
componentWillMount(){
this.props.getData();//进行api调用
this.setState({data:this.props.data});//获取存储在存储中的数据
}

当您调用
getData()
时,浏览器将完成它的工作,并且您的redux状态最终将更新,因此,当调用第二行时,数据还不存在


您可以使用一些承诺和/或
async/await
函数,但实际上并不需要。您可以使用常规的组件生命周期功能,更好的是,您可以使用
this.props.data
而不具有任何内部状态。

仅供参考,组件将接收props。请看。也。
export const INITIAL_STATE = Immutable({});
export const updateData = (state, action) => {
  console.log('reducers', action.data);
  return { ...state, ...action.data };
};

const ACTION_HANDLERS = {
  [UPDATE_DATA]: updateData,
};

export default createReducer(INITIAL_STATE, ACTION_HANDLERS);