Question about createContainer + React + performance


#1

My question is:

Does the createContainer object stop tapping into the subscription feed once the component it’s attached to unmounts?

As my application becomes larger and larger, I find myself having to subscribe to certain MongoDB instances repeatedly and fear that it would impact performance in the future. Logically, I think that after the component that the container is attached to unmounts, the subscription feed should stop for that particular component.

For example, I have this container, which is attached to the Plans React component:

export default createContainer(() => {
  const users = Meteor.subscribe("userData");
  userData = new ReactiveVar(false);

  users.ready() ? userData.set(true) : userData.set(false);

  return{
    user: Meteor.users.find().fetch()
  }
}, Plans)

I would expect this container to disengage after the Plans component unmounts and not dip into the subscription feed until I navigate back to the Plans component. By the way, I also use componentShouldUpdate() throughout my app for more performance tweaks where applicable.

Am I assuming correctly?


#2

Yes - subscriptions stop when the component is unmounted.