mobx: Dynamic observable cannot be frozen.

This issue also refers to this one #1881 I am having the following issue and it can be recreated as follows:

The allVehicles variable is an array of string IDs;

    @observable allVehicles;

    @action setAllVehicles(vehiclesID) {
        this.allVehicles = vehiclesID;
    }
}

Then here the VehiclesStore.setSelectedObject sets the selectVehicle to an observable variable inside the VehiclesStore, based on the vehicleID i find witch vechicle from VehiclesStore.objects i need to have selected. The VehiclesStore.objects is also an observable array of objects

selectVehicle(vehicleID) {
    let selectVehicle = VehiclesStore.objects.find(vehicle => vehicle.id === vehicleID);
    VehiclesStore.setSelectedObject(selectVehicle);
  }

Based on the allVehicles observable i’m creating a list of PickerItems like so, The value of one entry of the allVehicles array looks like this: <Picker.Item key = {'myID'} value = {'vehicleID'} label = {'Plate'}/>

<Picker 
          style = {{ width: '100%'  }}
          mode = { "dropdown" }
          prompt = {"Select a vehicle"}
          onValueChange = {(vehicleID) => {
              console.log(vehicleID); **THIS IS NEVER REACHED**
              this.selectVehicle(vehicleID);
              this.props.props.navigate('Details', {props: this.props});
          }}
        > 
          {VehiclesStore.allVehicles}
        </Picker>

I hope that this information it’s helpful.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 15 (6 by maintainers)

Most upvoted comments

At first glance it sounds like you are pasisng observable data to Picker where you shouldn’t, since it doesn’t understand them. Try to toJS your value first

Op ma 11 feb. 2019 om 09:58 schreef itamar sharify <notifications@github.com

:

here is a working react-native codesandbox: https://codesandbox.io/s/zlkv3rpqqm can you try to reproduce it here?

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/mobxjs/mobx/issues/1900#issuecomment-462255404, or mute the thread https://github.com/notifications/unsubscribe-auth/ABvGhNq2P7hTBo46bKpBeMnio3GamfjOks5vMTCggaJpZM4azq6v .