0

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
}
Nilupul Heshan
  • 580
  • 1
  • 5
  • 18
  • 2
    What's the reason why you want to detect this? React is primarily declarative, not imperative, so generally your logic should be based on your data, not whether or not it updates. – Nick McCurdy Dec 21 '20 at 05:31
  • If it's a state object, it doesn't matter how complex it is, react will rerender if it is changed with setState – Jordan Dec 21 '20 at 05:32
  • I want to send an update request if the object is changed from the previous state – Nilupul Heshan Dec 21 '20 at 09:13

1 Answers1

2

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.