Skip to content

Instantly share code, notes, and snippets.

@khg0712
Created May 28, 2023 18:16
Show Gist options
  • Save khg0712/4d6bcadf3da299c0ba9f74c36f21b787 to your computer and use it in GitHub Desktop.
Save khg0712/4d6bcadf3da299c0ba9f74c36f21b787 to your computer and use it in GitHub Desktop.
// packages/next/client/with-router.tsx
// withRouter 코드
// https://github.com/vercel/next.js/blob/v12.3.4/packages/next/client/with-router.tsx#L19
import { useRouter } from './router'
export default function withRouter<
P extends WithRouterProps,
C extends BaseContext = NextPageContext
>(
ComposedComponent: NextComponentType<C, any, P>
): React.ComponentType<ExcludeRouterProps<P>> {
function WithRouterWrapper(props: any): JSX.Element {
return <ComposedComponent router={useRouter()} {...props} />
}
// ...
return WithRouterWrapper
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment