parse-community / ParseReact

Seamlessly bring Parse data into your React applications.
https://parseplatform.org
Other
1.3k stars 209 forks source link

Queries depending on other queries? #124

Closed rubencodes closed 9 years ago

rubencodes commented 9 years ago

This is more a question of practices than an issue (though I suppose it's an issue in that I don't know if this is possible), but I have a special case where I need to make a query based off of info I get from another query. Ideally I want to do this in the same component. Is this possible?

e.g. the way I have it set up right now using only Parse and React (not Parse-React) is:

var QueryOne = new ParseQuery("QueryOne");
QueryOne.find({
  success: function(results) {
    var listOfThingsToGetFromQueryTwo = results.attributes.listOfThingsToGetFromQueryTwo;

    var QueryTwo = new ParseQuery("QueryTwo").containedIn("id", listOfThingsToGetFromQueryTwo);
  }
});

Using Parse-React, can I make a component observe (in this example) QueryTwo AND QueryOne?

rubencodes commented 9 years ago

I naively set out to implement this using parse-react by observing a query in one component and passing that data as a prop to a secondary component, but I realize now that the observe function isn't called on prop updates so the query isn't rerun. Really need a way around this...Perhaps some way of triggering the query to rerun from componentWillUpdate?

rubencodes commented 9 years ago

Got it! Turns out the observe function is passed newProps and newState as parameters, so if I set the props in the parent container, I can use in the containedIn filter on the child, and it works.