rsnext/packages/next/client/with-router.tsx
Tim Neutkens 355078c350
Separate toRoute function (#6766)
Because Typescript output is turned to commonjs for these modules currently it’s better to do this. Also convert withRouter to typescript, making it smaller.
2019-03-23 23:00:46 +01:00

22 lines
549 B
TypeScript

import React from 'react'
import PropTypes from 'prop-types'
export default function withRouter(ComposedComponent: React.ComponentType<any> & {getInitialProps?: any}) {
class WithRouteWrapper extends React.Component {
static getInitialProps?: any
static contextTypes = {
router: PropTypes.object,
}
render() {
return <ComposedComponent
router={this.context.router}
{...this.props}
/>
}
}
WithRouteWrapper.getInitialProps = ComposedComponent.getInitialProps
return WithRouteWrapper
}