TypeError: Cannot read properties of undefined (reading ‘id’)

What is happening:

The function itemToForm() is being called before the this.item is ready.

There are many strategies to avoid this error. A very simple one is to add a catcher at the beginning of the function, like this:

itemToForm = () => {
  if(this.item === undefined) {return}
         
  // The rest of the code
}

This stops the function, if the data does not exist yet.

A more elegant solution may be to go further up in your order of operations, and find who is calling itemToForm() and ensure the data exists prior to calling.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)