Home > OS >  Uncaught TypeError: Cannot read properties of undefined (reading 'start_time')
Uncaught TypeError: Cannot read properties of undefined (reading 'start_time')

Time:02-02

I am facing this error when I update my last end time of last interval although it updates my state but not showing it in table

enter image description here

 const onEdit = (oldValue, newValue, row, column) => {
    const oldRows = props.row;
    console.log("BHai", props.row.length - 1);
    if (column.dataField === "end_time") {
      if (newValue < oldRows[row.interval   1].start_time) {
        oldRows[row.interval][column.dataField] = newValue;
        const startTime = parseInt(row.start_time);
        const endTime = parseInt(row.end_time);
        props.onIntervalUpdate([startTime, endTime], row.interval);
        console.log("BHai1");
      } else if (oldRows[row.interval].interval === props.row.length - 1) {
        oldRows[row.interval][column.dataField] = newValue;
        const startTime = parseInt(row.start_time);
        const endTime = parseInt(row.end_time);
        props.onIntervalUpdate([startTime, endTime], row.interval);
        console.log("BHai2");
      } else {
        oldRows[row.interval][column.dataField] = oldValue;
        const startTime = parseInt(row.start_time);
        const endTime = parseInt(row.end_time);
        props.onIntervalUpdate([startTime, endTime], row.interval);
        console.log("BHai3");
      }
    }

enter image description here

CodePudding user response:

Consider adding Optional chaining (?.) during destructuring, as:

newValue < oldRows[row.interval   1]?.start_time)

and

 const startTime = parseInt(row?.start_time);

CodePudding user response:

figured it out like this,

if (
        oldRows[row.interval].interval === props.row.length - 1 &&
        oldRows[row.interval].start_time
      )

working fine for me

  •  Tags:  
  • Related