Error: Property ‘myRef’ does not exist on type ‘MyComponent

We face below error while using ref in our ReactJS application.

Error: Property ‘myRef’ does not exist on type ‘MyComponent

To resolve this error, declare your ref variable inside the class component

export default class MyComponent extends React.Component<IMyComponentProps, any> {
  private myRef;
  constructor(props) {
    super(props);
    this.myRef = React.createRef();
  }
}

Author: Akanksha Gupta

I am a developer and working on SharePoint and Project Server in an MNC. I have more than 10 years of experience in the same field.

Leave a comment

Power Platform Academy

Start or Upgrade your Career with Power Platform

Learn with Akanksha

Python | Azure | AI/ML | OpenAI | MLOps