公司react项目分析学习

一、路由

https://blog.csdn.net/qq_43720551/article/details/136333256

使用`lazy`和`Suspense`组件进行懒加载,以提高初始加载速度。通过`import()`动态导入模块,当LazyComponent加载较慢时,会显示备用UI,直到组件完成加载。

Suspense组件当页面没有加载出来时先展示loadding

懒加载 
import React from 'react';
import { lazy, Suspense } from 'react';
const LazyComponent = lazy(() => import('./TestThree'));
export default class TestTwo extends React.Component<{}> {
    state = {

    }
    public render() {
        return (
            <div>
                <h1>My App</h1>
                <Suspense fallback={<div>Loading...</div>}>
                    <LazyComponent />
                </Suspense>
            </div>

        )
    }
}

 

posted @ 2024-09-29 11:39  凯宾斯基  阅读(18)  评论(0)    收藏  举报