Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

componentWillMount vs componentDidMount #242

Closed
crapthings opened this issue Dec 29, 2017 · 3 comments
Closed

componentWillMount vs componentDidMount #242

crapthings opened this issue Dec 29, 2017 · 3 comments

Comments

@crapthings
Copy link

crapthings commented Dec 29, 2017

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
Copy link
Author

crapthings commented Dec 29, 2017

some issue relative to this.

meteor/guide#33 (comment)

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

@dburles
Copy link
Contributor

dburles commented Aug 8, 2018

@crapthings PR definitely welcome 😊

@filipenevola
Copy link
Collaborator

closing because of [email protected] #273

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants