javascript - Property 'ref' does not exist on type 'A'.ts(2339) - React, TypeScript - Stack Over

Error:Property 'ref' does not exist on type 'A'.ts(2339)Here is my source codeexpo

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?

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?

Share asked Aug 7, 2020 at 17:29 merry-go-roundmerry-go-round 4,63513 gold badges59 silver badges112 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

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();

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744908103a4600378.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信