Error:
Property 'ref' does not exist on type 'A'.ts(2339)
Here is my source code
export default class A extends React.PureComponent<Props, State> {
constructor(props: Props) {
super(props);
this.ref = React.createRef(); << ERROR HERE
How can I define type of A to resolve the error?
You have to declare the ref variable in the class body.
export default class A extends React.PureComponent<Props, State> {
ref: React.RefObject<HTMLInputElement>;
constructor(props: Props) {
super(props);
this.ref = React.createRef();
}
}
or basically remove the constructor and move logic outside.
export default class A extends React.PureComponent<Props, State> {
ref = React.createRef();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With