如何在React 16.6.3中调试Lazy,Suspense后备

时间:2018-12-04 12:48:59

标签: javascript reactjs lazy-loading

我需要在react 16.6.3中调试Lazy,Suspense fallback

需要更新加载界面。

寻找最佳解决方案。

https://reactjs.org/blog/2018/10/23/react-v-16-6.html#reactlazy-code-splitting-with-suspense

1 个答案:

答案 0 :(得分:1)

import React, {lazy, Suspense} from 'react';
const OtherComponent = lazy(() => import('./OtherComponent'));

function MyComponent() {
  return (
    <Suspense fallback={<Fallback />}>
      <OtherComponent />
    </Suspense>
  );
}

function Fallback() {
  // debug it here to your heart's content
  // same thing with "OtherComponent", debug it in component
  return <div>Loading...</div>;
}