Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

App.js:69 Uncaught TypeError: Cannot read properties of undefined (reading 'setState')

Can anyone help me, I am getting this error "App.js:69 Uncaught TypeError: Cannot read properties of undefined (reading ‘setState’)
at onInputChange (App.js:69:1)"
Code Snippet

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Few ways to go about this.

Since you’re not using arrow function you need to bind your handlers

constructor() {
  ...code
  this.onInputChange = this.onInputChange.bind(this)
  this.onButtonSubmit = this.onInputChange.bind(this)
}

option 2 – switch your function to arrow function

onInputChange = (event) => {
  ...code
}

onButtonSubmit = () => {
  ...code
}

Here’s a helpful post to help you understand why

https://www.freecodecamp.org/news/this-is-why-we-need-to-bind-event-handlers-in-class-components-in-react-f7ea1a6f93eb/

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading