meteor / react-packages

Meteor packages for a great React developer experience
http://guide.meteor.com/react.html
Other
574 stars 159 forks source link

componentWillMount vs componentDidMount #242

Closed crapthings closed 5 years ago

crapthings commented 6 years ago

https://github.com/meteor/react-packages/blob/devel/packages/react-meteor-data/ReactMeteorData.jsx#L127

componentWillMount vs componentDidMount

what is different between

componentWillMount() {
  this.data = {};
  this._meteorDataManager = new MeteorDataManager(this);
  const newData = this._meteorDataManager.calculateData();
  this._meteorDataManager.updateData(newData);
}
componentDidMount() {
  this.data = {};
  this._meteorDataManager = new MeteorDataManager(this);
  const newData = this._meteorDataManager.calculateData();
  this._meteorDataManager.updateData(newData);
}

if we use react-router or flow-router + react-mounter then we make a subscribe withTracker

when switching route, next component's componentWillMount will happen before previous component's componentWillUnmount. is this a correct behavior?

this will cause minimongo's remain previous subscription's records, it reruns component while previous records are removed one by one.

the ddp message is always show sub first then unsub

image

this will cause unwanted rerun, screen flick.

then i try to make a container like what react-meteor-data does then move subscribe to "componentDidMount" and "componentWillUnmount" to stop tracker first and subscribeHandler

image

image

the order looks good now, and stop subscribe does what meteor docs said

image

stop() Cancel the subscription. This will typically result in the server directing the client to remove the subscription’s data from the client’s cache.

crapthings commented 6 years ago

some issue relative to this.

https://github.com/meteor/guide/issues/33#issuecomment-151716789

Clean client side minimongo? https://github.com/meteor/meteor-feature-requests/issues/242

dburles commented 6 years ago

@crapthings PR definitely welcome 😊

filipenevola commented 5 years ago

closing because of react-meteor-data@2.0.0 https://github.com/meteor/react-packages/pull/273