如何延迟 componentDidMount API 在 React 中获取?

How to delay componentDidMount API fetching in React?

我正在使用 Axios 获取数据并希望延长加载动画的时间(出于个人原因)。

  componentDidMount(){
    var that = this;
    axios.get('api.something.io.json', {
        params: data
      })
      .then(function (response) {
        console.log(response);
        that.setState({
          axiosResponse: response.data,
          isLoading: false
        })
      })
      .catch(function (error) {
        console.log(error);
      });
  };
  ...
  render() {
    if(this.state.isLoading){
      return <div>Waiting...</div>
    }

    return (
      <div className="App">
        <h1>{this.state.axiosResponse.awesomeTitle}</h1>
      </div>
    );

现在 Waiting... 在主要组件呈现之前显示一瞬间。我想将 "Waiting..." 延长一点,大约 2-3 秒。我尝试在 componentDidMount 上使用 ,但它似乎没有用。

componentDidMount(){
  setTimeout(this.setState({isLoading: 1}), 3000);
  //do axios call here
}

我还尝试在 .then 调用中存根 setTimeout:

  componentDidMount(){
    var that = this;
    axios.get('https://api.rss2json.com/v1/api.json', {
        params: data
      })
      .then(function (response) {
        console.log(response);
        setTimeout(
          that.setState({
            axiosResponse: response.data,
            isLoading: false
          })
          , 3000);

      })
  ...

None 有效。如何将 isLoading 延长 3 秒?

setTimeout 接受函数作为第一个参数:

    setTimeout(function() {
      that.setState({
        axiosResponse: response.data,
        isLoading: false
      })
     }, 3000); 

而不是:

     setTimeout(
          that.setState({
            axiosResponse: response.data,
            isLoading: false
          }), 3000);