I’m just starting to learn Meteor using React as the view layer and I stumble upon a problem of updating the query that is provided in createContainer() method.
In the tutorial of React it’s recommended that you do the query in the createContainer() method stated in collections section of the tutorial like below:
Check out this forum thread, and in particular this response:
You could leverage one of the many available state management methods (ReactiveVar, ReactiveDict/Session, Redux, etc.) to access a sort field/order that was selected in some other component, and use it in your createContainer function.
Do you have sample code snippet to demonstrate this? I tried using the ReactiveVar but when I use it’s #set() mtehod it doesn’t trigger re-rendering of the container:
Sure - I’ve thrown together a quick example below. The issue with your code snippet is that you’re initializing your ReactiveVar within the createContainer() function. Each time createContainer is called, you’re clobbering your new ReactiveVar value. Here’s a quick example showing how you can work around this:
Thanks @hwillson! It is working great now. I missed that the callback function you passed to createContainer() method will be re-executed if there is a change in your data subscriptions, which in our case the ReactiveVar.