Skip to content

componentWillMount vs componentDidMount #242

Closed
@crapthings

Description

@crapthings

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions