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

Commits on Aug 3, 2021

  1. Require component rendered as child of Link to pass event to `onCli…

    …ck` handler
    
    Currently, if you render `next/link` like
    
    ```ts
    <Link>
      <CustomComponent />
    </Link>
    ```
    
    and have 
    
    ```tsx
    interface Props {
      onClick?: () => void; // <— note we're not passing event as an argument
    }
    
    function CustomComponent({ onClick }: Props) {
      return <div onClick={() => onClick?.()}>Hello</div>
    }
    ```
    
    It'll result in error
    
    ```
    link.js?f421:21 Uncaught TypeError: Cannot read property 'defaultPrevented' of undefined
    ```
    pie6k committed Aug 3, 2021
    Copy the full SHA
    bb9a687 View commit details
    Browse the repository at this point in the history

Commits on Feb 6, 2022

  1. Copy the full SHA
    70536b9 View commit details
    Browse the repository at this point in the history
  2. Update check and add test

    ijjk committed Feb 6, 2022
    Copy the full SHA
    cf44f9b View commit details
    Browse the repository at this point in the history