dispatch an action on componentDidMount (react/redux)

前端 未结 4 745
有刺的猬
有刺的猬 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条回答
  •  猫巷女王i
    2021-02-18 17:07

    Yes, dispatching an action on componentDidMount() is OK, and even the recommended thing to do since it will not slow down the initial UI render.

    Since the function runs after the component has initially rendered, keep in mind that you may have sometime between the moment the component is rendered, and the moment you receive the data from the api call.

提交回复
热议问题