Skip to content

Explain why componentDidMount is a better place to make an ajax request #302

Open
@coatlicue89

Description

@coatlicue89

In the docs, in componentWillMount section section it says:

Avoid introducing any side-effects or subscriptions in this method

And in the componentDidMount section:

If you need to load data from a remote endpoint, this is a good place to instantiate the network request

Which for me is confusing because I won't like to wait for the component to be mounted to dispatch an ajax call to fulfill the component data dependencies. I would like to do it as soon as possible, like in the constructor, not even in componentWillMount.

Clearly you may have a reason why you say this in the docs, I might be not seeing the bigger picture. So it will be nice if you can explain a bit more in detail or point me in the direction of where I can find the reason.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions