const DoctorResearchArticle = props => {
console.log('props.doctor_indi_articles', props.doctor_articles); //here can able to access redux store data after triggerring the dispatch action at line no 6
const handle_edit_click = async (id) => {
await props.doctor_ind_article(id);
console.log('props.doctor_indi_articles', props.doctor_articles);
// here after triggerring the api and dispatching the data to store, at the initial time it shows null
}
}
const mapDispatchToProps = (dispatch) => {
return {
doctor_ind_article: (article_id) =>dispatch(getDocIndivisualArti(article_id)),
}
}
const mapStateToProps = (state) => {
return {
doctor_articles: state.doctor.doctor_ind_article
};
};
export default connect(
mapStateToProps,
mapDispatchToProps
)(DoctorResearchArticle);
这里的问题是redux数据最初显示为null,在代码中发布的主要组件的函数内调用调度动作后,重要的是,在调用调度动作时触发get api并将数据存储到redux store状态也更新了。问题是我们可以访问主组件内的 redux 存储数据,但不能访问主组件内的函数。如果我在主组件中记录道具数据,它会显示更新的状态数据,但如果在函数内记录相同的内容,那么最初它会显示为 null,然后它会加载(记录)数据。这让我很困扰。关于这一点,我尝试使用 store.subcribe(listener) 函数在主组件内部更新存储时获取数据。它有效,但需要太多时间。所以这不适合我的情况。所以非常感谢任何帮助。谢谢。