Update types for with-router (#7106)
* Updated declarations for with-router
This commit is contained in:
parent
baabfbd777
commit
db5b3dc8e3
1 changed files with 13 additions and 3 deletions
|
@ -1,18 +1,28 @@
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
|
import { NextComponentType, IContext } from 'next-server/dist/lib/utils'
|
||||||
|
import { IPublicRouterInstance } from './router';
|
||||||
|
|
||||||
export default function withRouter(ComposedComponent: React.ComponentType<any> & {getInitialProps?: any}) {
|
export type WithRouterProps = {
|
||||||
class WithRouteWrapper extends React.Component {
|
router: IPublicRouterInstance,
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ExcludeRouterProps<P> = Pick<P, Exclude<keyof P, keyof WithRouterProps>>
|
||||||
|
|
||||||
|
export default function withRouter<P extends WithRouterProps, C = IContext>(ComposedComponent: NextComponentType<C, any, P>): React.ComponentClass<ExcludeRouterProps<P>> {
|
||||||
|
class WithRouteWrapper extends React.Component<ExcludeRouterProps<P>> {
|
||||||
static displayName?: string
|
static displayName?: string
|
||||||
static getInitialProps?: any
|
static getInitialProps?: any
|
||||||
static contextTypes = {
|
static contextTypes = {
|
||||||
router: PropTypes.object,
|
router: PropTypes.object,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context!: WithRouterProps
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return <ComposedComponent
|
return <ComposedComponent
|
||||||
router={this.context.router}
|
router={this.context.router}
|
||||||
{...this.props}
|
{...this.props as any}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue