Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require component rendered as child of Link to pass event to onClick handler #27723

Merged
merged 3 commits into from Feb 7, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/next/client/link.tsx
Expand Up @@ -282,6 +282,11 @@ function Link(props: React.PropsWithChildren<LinkProps>) {
} = {
ref: setRef,
onClick: (e: React.MouseEvent) => {
if (!e) {
if (process.env.NODE_ENV !== 'production') {
ijjk marked this conversation as resolved.
Show resolved Hide resolved
throw new Error(`Component rendered inside Link has to pass click event to "onClick" prop.`)
}
}
if (child.props && typeof child.props.onClick === 'function') {
child.props.onClick(e)
}
Expand Down