dispatch an action on componentDidMount (react/redux)

前端 未结 4 725
有刺的猬
有刺的猬 2021-02-18 16:41

I am relativity new to react/redux. There for I want to ask a (perhaps a philosophic) question.

Is it ok to to dispatch an action (e.g. to trigger an api-call) on

4条回答
  •  旧巷少年郎
    2021-02-18 17:06

    When using routes another recommended way to dispatch an action would be the routes-method "onEnter". This is in order to make the component not dependent from actions (or api-calls).

    I personally think both methods (componentDidMount vs. onEnter) are ok. It is left to the programmer to choose which solution is best for his application.

提交回复
热议问题