-1

Mobx store:

Contains array of object of type person, Person class has nested array, other class methods(Assume we don't have ID so we are not creating Map)

@observable persons: Person[] = []
@observable selectedPerson: Person;

@action setSelectedPerson(person) {
   //How to clone person from list of persons as observable object ?
   // tried person.find() etc did't work
   // if person.deleteAddress() is called change is not detected in UI.
}
ksh
  • 639
  • 1
  • 7
  • 23

1 Answers1

0

I've tried to reproduce your case https://codesandbox.io/s/httpsstackoverflowcomquestions63363594-3eisd?file=/src/App.js (please, try to provide such examples by yourself next time, if possible), but could not achieve such scenario.

Just doing this thing

  @action setSelectedPerson(person) {
    this.selectedPerson = person;
  }

should do the trick. You don't need to clone this object, just set the reference to it basically. Everything will work out of the box. One thing I can assume that you forgot to mark person address as observable

Danila
  • 15,606
  • 2
  • 35
  • 67