forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prefetch.js
33 lines (28 loc) · 875 Bytes
/
prefetch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import React from 'react'
import Link from './link'
import Router from './router'
import { warn, execOnce } from './utils'
const warnImperativePrefetch = execOnce(() => {
const message = '> You are using deprecated "next/prefetch". It will be removed with Next.js 2.0.\n'
'> Use "Router.prefetch(href)" instead.'
warn(message)
})
const wantLinkPrefetch = execOnce(() => {
const message = '> You are using deprecated "next/prefetch". It will be removed with Next.js 2.0.\n'
'> Use "<Link prefetch />" instead.'
warn(message)
})
export function prefetch (href) {
warnImperativePrefetch()
return Router.prefetch(href)
}
export default class LinkPrefetch extends React.Component {
render () {
wantLinkPrefetch()
const props = {
...this.props,
prefetch: this.props.prefetch !== false
}
return (<Link {...props} />)
}
}