All files / src/chap05 LazyMulti.js

0% Statements 0/10
100% Branches 0/0
0% Functions 0/7
0% Lines 0/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16                               
import { Suspense, lazy } from 'react';
 
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
 
// 여러 컴포넌트 지연 로드
const LazyButton = lazy(() => sleep(2000).then(() => import('./LazyButton')));
const LazyButton2 = lazy(() => sleep(1000).then(() => import('./LazyButton2')));
 
export default function LazyMulti() {
  return (
    <Suspense fallback={<p>Now Loading...</p>}>
      <LazyButton />
      <LazyButton2 />
    </Suspense>
  );
}