I am relatively new to React and looking to see how easy it would be to migrate to it from Blaze. I have picked a component to rewrite in React which contains a tree structure of nodes, but struggling with subscriptions.
I have created the following container
import { createContainer } from 'meteor/react-meteor-data';
export default createContainer (() => {
return {
openNodes: Session.get("openNodes"),
selectedNodeId: Session.get("selectedNodeId"),
getChildNodes: (node) => {
Meteor.subscribe("nodesByParent", node['_id']});
return Nodes.find({parentId: node['_id']}).fetch();
}
};
}, NodeWrapper);
The properties from Session work fine e.g. openNodes, selectredNodeId. However, when I call the getChildNodes method I see something strange. Using the ‘mongol’ tool (which allows me to see what is in minimongo), I can see the documents from the subscription appear and then instantly disappear.
Can someone please point me to the correct way to call a subscription with a parameter. Note: The getChildNodes method will not always be called - it only needs to be called when a user expands a node in the tree.