The handling documentation states that the ajax request must be triggered from the componentDidMount lifecycle event (see edit documents ).
Why is this event?
In most cases, when loading data using ajax, I want to display some loading panel, for example:
componentDidMount() { this.setState({isLoading: true}); fetch(...) .then(...) .then(() => this.setState({isLoading: false}) }
but this calls the render method 3 times (the initial render immediately after setting isLoading = true , and then isLoading = false
What happened to sending an ajax request from componentWillMount event?
source share