All of the examples and tutorials of NextJs pages which presented in its docs and other references are with functional components.
So, What about classes? What happens to getInitialProps (or other features that mentioned in docs) when a functional component replaces with an ES6 class. Is that page still a NextJS page after replacing?
The contract is that you export a React component, which can be a function or a class, for example:
import React from 'react'
export default class SomePage extends React.Component {
static async getInitialProps() {
return {}
}
render() {
return <div>test</div>
}
}
Class components work fine when exported 馃憤
The docs mention exporting class components too btw: https://github.com/zeit/next.js#fetching-data-and-component-lifecycle
Most helpful comment
The contract is that you export a React component, which can be a function or a class, for example:
Class components work fine when exported 馃憤
The docs mention exporting class components too btw: https://github.com/zeit/next.js#fetching-data-and-component-lifecycle