39761e5ce7
* Remove `withAmp` and do not expose `isInAmpMode`
This pull request removes the `withAmp` higher-order component in favor of the exported configuration object.
Retaining this backwards compatibility isn't worth the extra maintenance burden, given it hasn't been released for very long and the migration is ultra-simple.
I'm 👎 on retaining backwards compatibility just for the sake of it.
Migration example follows. I'm willing to write a codemod if reviewers feel it's necessary.
*Before*
```js
import { withAmp } from 'next/amp'
function Home() {
return <h1>My AMP Page</h1>
}
export default withAmp(Home)
// or
export default withAmp(Home, { hybrid: true })
```
*After*
```js
export default function Home() {
return <h1>My AMP Page</h1>
}
export const config = {
amp: true,
// or
amp: 'hybrid',
}
```
* Fix { amp: 'hybrid' }
Co-Authored-By: JJ Kasper <jj@jjsweb.site>
16 lines
415 B
TypeScript
16 lines
415 B
TypeScript
import React from 'react'
|
|
import { AmpStateContext } from './amp-context'
|
|
|
|
export function isInAmpMode({
|
|
ampFirst = false,
|
|
hybrid = false,
|
|
hasQuery = false,
|
|
} = {}) {
|
|
return ampFirst || (hybrid && hasQuery)
|
|
}
|
|
|
|
export function useAmp() {
|
|
const ampState = React.useContext(AmpStateContext)
|
|
// un-comment below to not be considered AMP in dirty mode
|
|
return isInAmpMode(ampState) // && ampMode.hasQuery
|
|
}
|