
我如何实现最初的页面加载动画,一堆灰色块,加载动画,直到实际内容呈现在下一个Js中。我有图书馆吗?
发布于 2022-07-07 16:28:42
使用React 18,使用React.Suspense API进行回退。
https://reactjs.org/docs/react-api.html#reactsuspense
// This component is loaded dynamically
const OtherComponent = React.lazy(() => import('./OtherComponent'));
function MyComponent() {
  return (
    // Displays <Spinner> until OtherComponent loads
    <React.Suspense fallback={<Spinner />}>
      <div>
        <OtherComponent />
      </div>
    </React.Suspense>
  );
}其中,spinner可以是一个组件,它是从这样一个很好的资源构建的
更多选项
https://stackoverflow.com/questions/72901071
复制相似问题