提交 01779429 编写于 作者: S Simon Boudrias 提交者: Tim Neutkens

Set descriptive displayName on withRouter HOC (#7017)

Not sure when it was introduced, but on the latest Next v8.0.4, there's no descriptive name attached to the component returns from `withRouter`.

This makes it harder to debug and write test cases for components wrapped by `withRouter`.
上级 a0473e1f
......@@ -3,6 +3,7 @@ import PropTypes from 'prop-types'
export default function withRouter(ComposedComponent: React.ComponentType<any> & {getInitialProps?: any}) {
class WithRouteWrapper extends React.Component {
static displayName?: string
static getInitialProps?: any
static contextTypes = {
router: PropTypes.object,
......@@ -17,6 +18,10 @@ export default function withRouter(ComposedComponent: React.ComponentType<any> &
}
WithRouteWrapper.getInitialProps = ComposedComponent.getInitialProps
if (process.env.NODE_ENV !== 'production') {
const name = ComposedComponent.displayName || ComposedComponent.name || 'Unknown'
WithRouteWrapper.displayName = `withRouter(${name})`
}
return WithRouteWrapper
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册