ReactJS: Suspense
@loadable/component có một phương thức là lazy đóng vai trò tương tự như phương thức React.lazy.
import React, { Suspense } from 'react' import { lazy } from '@loadable/component' const OtherComponent = lazy(() => import('./OtherComponent')) function MyComponent() { return ( <div> <Suspense fallback={<div>Loading...</div>}> <OtherComponent /> </Suspense> </div> ) }
Sử dụng
lazy.libcho thư viện.
⚠️ Tính năng Suspense không áp dụng được cho hiển thị phía máy chủ.