okland / camera-ui

Meteor package for taking photos with user interface, one function call on desktop and mobile. Allows to choose between camera to photoLibrary on mobile.
28 stars 12 forks source link

How to setState in callback instead of Session variable? #3

Open ghost opened 8 years ago

ghost commented 8 years ago

Hello,

I'm trying to save state in callback like

MeteorCameraUI.getPicture( { cameraOptions }, function( error, data ) {
      if (error) {
        console.log(error);
      } else {
        this.setState({
          image_data: data
        });
      }
    });

... getting: TypeError: this.setState is not a function

Also tried with setting binding like this

MeteorCameraUI.getPicture( { cameraOptions }, function( error, data ) {
      if (error) {
        console.log(error);
      } else {
        this.setState({
          image_data: data
        });
      }
    }.bind(this));

same result.

ghost commented 8 years ago

Just realised... put in constructor this:

constructor(props, context) {
    super(props, context);
    this.onAddPhoto = this.onAddPhoto.bind(this);

onAddPhoto is method where I run MeteorCameraUI