The console is showing a new Object but I still get the error
const GetNo = (): string => {
console.log(record);
if (record.no !== "")
return record.no; //<-- Cannot read properties of undefined
else
return todos[todos.length - 1].no + 1;
}
console:
EDIT:
record is type of object (see picture above) and im creating it via Button onClick where i modify a state this.setState({ selectedRecord: new ToDoClass() . After that I redner the FC with the form.
EDIT 2: I tried the new Syntax:
const GetNo = (): string => {
if (record == null) {
console.log("1");
return "2";
}
else if (record.no != null) {
console.log("2");
return record.no;
}
else {
console.log("3");
return todos[todos.length - 1].no + 1;
}
}
and when the record is: new ToDoClass() it return in the console a 2 but it should go inside the first statement?!

recordand where is it initialized?const record = ....?