meteor / react-packages

Meteor packages for a great React developer experience

Home Page:http://guide.meteor.com/react.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

componentWillMount vs componentDidMount

crapthings opened this issue · comments

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.

some issue relative to this.

meteor/guide#33 (comment)

Clean client side minimongo?
meteor/meteor-feature-requests#242

@crapthings PR definitely welcome 😊

closing because of react-meteor-data@2.0.0 #273