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 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}) {
|
||||
class WithRouteWrapper extends React.Component {
|
||||
export type WithRouterProps = {
|
||||
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 getInitialProps?: any
|
||||
static contextTypes = {
|
||||
router: PropTypes.object,
|
||||
}
|
||||
|
||||
context!: WithRouterProps
|
||||
|
||||
render() {
|
||||
return <ComposedComponent
|
||||
router={this.context.router}
|
||||
{...this.props}
|
||||
{...this.props as any}
|
||||
/>
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue