Morgan Wilde
Morgan Wilde

Reputation: 17323

ParseReact.Mixin how do I listen for changes to this.data?

I have a React component that observes data on a Parse server.

mixins: [ParseReact.Mixin],
observe: function() {
   var query = new Parse.Query('Item');
   return {
      items: query
   };
}

In the render method I do receive my items and that work well. But, I want to be able to listen for when this.data.items will change it's value.

I'm aware of the regular lifecycle methods, but in them I have no way of checking if this.data.items is the same as before the update.

componentWillUpdate: function(nextProps, nextState) {},
componentDidUpdate: function(prevProps, prevState) {},

How do I do that?

Upvotes: 0

Views: 190

Answers (1)

Nobuhito Kurose
Nobuhito Kurose

Reputation: 558

You mean you need a "receiving data" callback?
Now there are no such a callback.
See this issue.

You can override "_receiveData" function in class extended ParseComponent by yourself though I'm not sure it's the right way for your situation.

_receiveData(name, value) {
  this.data[name] = value;
  delete this._pendingQueries[name];
  delete this._queryErrors[name];
  this.forceUpdate();
}

Upvotes: 1

Related Questions