You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The HOC withRouter should copy the prop-types and default-props definition from the wrapped component. This is currently not the case.
In order to implement this the following code may be used:
import React from 'react'
import Route from './Route'
/**
* A public higher-order component to access the imperative API
*/
const withRouter = (Component) => {
const C = (props) => (
<Route render={routeComponentProps => (
<Component {...props} {...routeComponentProps}/>
)}/>
)
C.displayName = `withRouter(${Component.displayName || Component.name})`
// Copy the prop-types as well as the default-props from the wrapped component:
C.propTypes = Component.propTypes
C.defaultProps = Component.defaultProps
return C
}
export default withRouter
The text was updated successfully, but these errors were encountered:
This isn't actually correct. withRouter's wrapper component isn't concerned with those props itself, so it shouldn't be validating them. Since we just pass though the props given to withRouter, they will be validated at the wrapped component level, as they should be.
If you need to access the wrapped component directly, #4838 should solve that for you when it lands.
The HOC
withRouter
should copy the prop-types and default-props definition from the wrapped component. This is currently not the case.In order to implement this the following code may be used:
The text was updated successfully, but these errors were encountered: