Skip to content

Commit

Permalink
Add example with forwardRef to readme (#8428)
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk authored and Timer committed Aug 19, 2019
1 parent 37c6669 commit 144eecd
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions packages/next/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,29 @@ export default About

Note: if passing a functional component as a child of `<Link>` you will need to wrap it in [`React.forwardRef`](https://reactjs.org/docs/react-api.html#reactforwardref)

**Example with `React.forwardRef`**

```jsx
import React from 'react'
import Link from 'next/link'

// `onClick`, `href`, and `ref` need to be passed to the DOM element
// for proper handling
const MyButton = React.forwardRef(({ onClick, href }, ref) => (
<a href={href} onClick={onClick} ref={ref}>
Click Me
</a>
))

export default () => (
<>
<Link href='/another'>
<MyButton />
</Link>
</>
)
```

**Custom routes (using props from URL)**

If you find that your use case is not covered by [Dynamic Routing](#dynamic-routing) then you can create a custom server and manually add dynamic routes.
Expand Down

0 comments on commit 144eecd

Please sign in to comment.