score:1

Accepted answer

the main problem is that you're using an id, which is inflexible and makes assumptions about the rest of the components (because ids must be globally unique).

module.exports = react.createclass({
  componentdidmount: function() {
    // pass a dom node to the constructor instead of it using an id
    this.component = new component(this.getdomnode());
    this.component.start();
  },

  componentwillunmount: function() {
    this.component.destroy();
  },

  render: function() {
    return <div />;
  }
});

your componentwillunmount was fine, but the one place you set this.component will always run before componentwillunmount, and there's no other reason it'd be assigned/deleted, so the if statement isn't needed.

also the arguments both weren't used, and aren't provided to componentwillunmount. that signature belongs to componentdidupdate.


Related Query

More Query from same tag