Skip to content

Instantly share code, notes, and snippets.

@khg0712
Created May 28, 2023 18:18
Show Gist options
  • Save khg0712/ff3f8afc2f032f22a9eeeda0d624782a to your computer and use it in GitHub Desktop.
Save khg0712/ff3f8afc2f032f22a9eeeda0d624782a to your computer and use it in GitHub Desktop.
// packages/next/client/index.ts
// Router 싱글톤을 저장하는 전역 객체
// https://github.com/vercel/next.js/blob/v12.3.4/packages/next/client/index.tsx#L67
export let router: Router
// AppContainer에서 RouterContext에 Router 싱글톤 주입하는 코드
// https://github.com/vercel/next.js/blob/v12.3.4/packages/next/client/index.tsx#L296
function AppContainer({
children,
}: React.PropsWithChildren<{}>): React.ReactElement {
return (
<Container>
<RouterContext.Provider value={makePublicRouterInstance(router)}>
{/* ... */}
</RouterContext.Provider>
</Container>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment