Skip to main content

Sharing data with context and React.cache

홈과 대시보드를 URL로 이동하면서 같은 getUser() 결과가 요청 단위에서 어떻게 재사용되는지 확인할 수 있습니다.

파일 구조

sharing-data-with-context-and-reactcache/
├── page.tsx
└── demo/
    ├── layout.tsx
    ├── page.tsx
    ├── dashboard/page.tsx
    ├── lib/user.ts
    ├── user-provider.tsx
    └── ui/profile.tsx

핵심 파일 코드

export const getUser = cache(async () => {
  return { id: 'u1', name: 'Next Learner' }
})

const userPromise = getUser()
return <UserProvider userPromise={userPromise}>{children}</UserProvider>
← 스터디로 돌아가기