I am building a reactredux dashboard application. I am from angular background so i am getting confuse here. What i really want to do is when i am in dashboard page i want to fetch data from api to show data in graphs. But the thing is here an action is not involved. Whenever i am in dashboard page i want to trigger that API to fetch data. Where should i make that request- In action or in the dashboard component. What is the best approach? In angular i just used to do ng-init from the view .
1条回答 默认 最新
- derek5. 2018-05-02 19:17关注
componentDidMount()
method is a good place to fetch data either of the component or enclosing one. If the component is redux aware probably should fetch in an action, and trigger that action when loading the component (same action that 'opens' the dashboard). Generally speaking there is no best approach and it is up to you to decide, one of the beauties of react it is not opinionated about your code structure and solves one thing only (how to render view fromstate
andprops
that is)解决 无用评论 打赏 举报
悬赏问题
- ¥60 优博讯DT50高通安卓11系统刷完机自动进去fastboot模式
- ¥15 minist数字识别
- ¥15 在安装gym库的pygame时遇到问题,不知道如何解决
- ¥20 uniapp中的webview 使用的是本地的vue页面,在模拟器上显示无法打开
- ¥15 网上下载的3DMAX模型,不显示贴图怎么办
- ¥15 关于#stm32#的问题:寻找一块开发版,作为智能化割草机的控制模块和树莓派主板相连,要求:最低可控制 3 个电机(两个驱动电机,1 个割草电机),其次可以与树莓派主板相连电机照片如下:
- ¥15 Mac(标签-IDE|关键词-File) idea
- ¥15 潜在扩散模型的Unet特征提取
- ¥15 iscsi服务无法访问,如何解决?
- ¥15 感应式传感器制作的感应式讯响器