在完成一个 API 请求之前停止加载 React JS / Flux 应用程序?

Stop React JS / Flux application loading until one API request is done?

我将 React JS 与 Alt (Flux) 库一起使用。

一开始我需要从 REST API 中获取用户数据。当此请求不成功时,我不想呈现整个应用程序并显示一些错误。如果成功获取数据,渲染应该继续。对于获取数据,我使用 Axios 库。

这个fetch data测试如何实现?

这是一个预先进行调用然后仅在调用成功时才呈现您的应用程序的解决方案。

axios.get('url')
  .then(function (response) {
    // success, let's render the app
    // you can pass the whole response object or just the data to your app
    ReactDOM.render(
        <MyApp reesponse={response}/>,
        document.getElementById('app')
    );
  })
  .catch(function (response) {
    // something went wrong
  });