Unverified Commit 9b999b1c authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Convert wrapper class to function component (#9095)

* Convert wrapper class to function component

* Remove unneeded export

* Check versions of chrome and chromedriver

* Update to chromedriver 76

* Revert config.yml

* Update with-router.tsx
parent d19e825d
...@@ -13,7 +13,7 @@ type SingletonRouterBase = { ...@@ -13,7 +13,7 @@ type SingletonRouterBase = {
ready(cb: () => any): void ready(cb: () => any): void
} }
export { Router, RouterContext, NextRouter } export { Router, NextRouter }
export type SingletonRouter = SingletonRouterBase & NextRouter export type SingletonRouter = SingletonRouterBase & NextRouter
......
import React from 'react' import React from 'react'
import { NextComponentType, NextPageContext } from '../next-server/lib/utils' import { NextComponentType, NextPageContext } from '../next-server/lib/utils'
import { NextRouter, RouterContext } from './router' import { NextRouter, useRouter } from './router'
export type WithRouterProps = { export type WithRouterProps = {
router: NextRouter router: NextRouter
...@@ -16,27 +16,19 @@ export default function withRouter< ...@@ -16,27 +16,19 @@ export default function withRouter<
C = NextPageContext C = NextPageContext
>( >(
ComposedComponent: NextComponentType<C, any, P> ComposedComponent: NextComponentType<C, any, P>
): React.ComponentClass<ExcludeRouterProps<P>> { ): React.ComponentType<ExcludeRouterProps<P>> {
class WithRouteWrapper extends React.Component<ExcludeRouterProps<P>> { function WithRouterWrapper(props: any) {
static displayName?: string return <ComposedComponent router={useRouter()} {...props} />
static getInitialProps?: any
static contextType = RouterContext
context!: React.ContextType<typeof RouterContext>
render() {
return <ComposedComponent router={this.context} {...this.props as any} />
}
} }
WithRouteWrapper.getInitialProps = ComposedComponent.getInitialProps WithRouterWrapper.getInitialProps = ComposedComponent.getInitialProps
// This is needed to allow checking for custom getInitialProps in _app // This is needed to allow checking for custom getInitialProps in _app
;(WithRouteWrapper as any).origGetInitialProps = (ComposedComponent as any).origGetInitialProps ;(WithRouterWrapper as any).origGetInitialProps = (ComposedComponent as any).origGetInitialProps
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
const name = const name =
ComposedComponent.displayName || ComposedComponent.name || 'Unknown' ComposedComponent.displayName || ComposedComponent.name || 'Unknown'
WithRouteWrapper.displayName = `withRouter(${name})` WithRouterWrapper.displayName = `withRouter(${name})`
} }
return WithRouteWrapper return WithRouterWrapper
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment