rsnext/packages/next/lib/with-router.js
Tim Neutkens 15bb1c5e79
Use Typescript to transpile Next.js core files instead of Babel (#5747)
- Replaces taskr-babel with taskr-typescript for the `next` package
- Makes sure Node 8+ is used, no unneeded transpilation
- Compile Next.js client side files through babel the same way pages are
- Compile Next.js client side files to esmodules, not commonjs, so that tree shaking works.
- Move error-debug.js out of next-server as it's only used/require in development
- Drop ansi-html as dependency from next-server
- Make next/link esmodule (for tree-shaking)
- Make next/router esmodule (for tree-shaking)
- add typescript compilation to next-server
- Remove last remains of Flow
- Move hoist-non-react-statics to next, out of next-server
- Move htmlescape to next, out of next-server
- Remove runtime-corejs2 from next-server
2018-11-28 15:03:02 +01:00

25 lines
658 B
JavaScript

import React, { Component } from 'react'
import PropTypes from 'prop-types'
import hoistStatics from 'hoist-non-react-statics'
import { getDisplayName } from 'next-server/dist/lib/utils'
export default function withRouter (ComposedComponent) {
const displayName = getDisplayName(ComposedComponent)
class WithRouteWrapper extends Component {
static contextTypes = {
router: PropTypes.object
}
static displayName = `withRouter(${displayName})`
render () {
return <ComposedComponent
router={this.context.router}
{...this.props}
/>
}
}
return hoistStatics(WithRouteWrapper, ComposedComponent)
}