dispatch an action on componentDidMount (react/redux)

前端 未结 4 730
有刺的猬
有刺的猬 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:10

    According to the official React documentation, componentDidMount is exactly the right place to do so:

    componentDidMount() is invoked immediately after a component is mounted. Initialization that requires DOM nodes should go here. If you need to load data from a remote endpoint, this is a good place to instantiate the network request.

    — Official React Documentation for componentDidMount()

提交回复
热议问题