javascriptreactjsobjectstateonreadystatechange

What is the easiest way to detect the state change of a complex object in Reactjs


I have a complex object as follows

const myObject = { 
                 title:"main title",
                 row:[
                       {rowTitle:"t1",index:1},
                       {rowTitle:"t2",index:2}
                 ],
                 column:[
                          {columnTitle:"c1",index:1},
                          {columnTitle:"c2",index:2},
                 ]
}

I need to detect if the properties change or not.

isObjectUpdated(myObject){
  // return true/false
}

Solution

  • In the case that you want the component / screen to be remounted if this object changes, you can use the useState() hook to achieve this behavior.