camera-ui icon indicating copy to clipboard operation
camera-ui copied to clipboard

How to setState in callback instead of Session variable?

Open ghost opened this issue 9 years ago • 1 comments

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 avatar Apr 26 '16 21:04 ghost

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

ghost avatar Apr 27 '16 08:04 ghost