I have two React class components:
Class A
import React from 'react';
import { withRouter } from 'react-router-dom';
export class A extends React.Component {
}
export default withRouter(A);
Class B
import React from 'react';
import { withRouter } from 'react-router-dom';
import A from './A';
export class B extends A {
}
export default withRouter(B);
When i render class B, i get ‘Class constructor cannot be invoked without ‘new” error. When i remove in Class A(parent of Class B) withRouter wrapper – all becomes fine. Why does this happen and what should i do to use exact this structure? Babel version/config? Router version? Anything else? Thank you.
>Solution :
You should inherit from the original component class A and not the wrapped version! For this you can use the static WrappedComponent property.
Corrected code:
export class B extends A.WrappedComponent {
}