Philip Giuliani
Philip Giuliani

Reputation: 1366

Check if all Child-Components have been mounted

Is there any way to detect if the childs have been mounted? When i initialize the Isotope, all children components must be mounted for the initialize. With a timeout of 5ms it is working like expected, but im sure there is a better way.

componentDidMount: function() {
    var container = this.refs.vinesOverview.getDOMNode();

    setTimeout(function() {
      var isotope = new Isotope(container, {
        itemSelector: ".vine_item",
        layoutMode: "masonry",
        resizable: true,
        gutter: 0,
        isFitWidth: true
      });

      this.setState({ isotope: isotope });
    }.bind(this), 5);
}

UPDATE

I have tried now this:

componentDidMount: function() {
    var container = this.refs.vinesOverview.getDOMNode();
    console.log(container.offsetHeight); // console output 0
    setTimeout(function() {
        console.log(container.offsetHeight); // console output 3150
    }, 5);
  },

So after 5ms it has calculated the height? Thats the reason why isotope isn't working. Is that a Bug or is that normal? Thanks!

Upvotes: 10

Views: 14705

Answers (1)

Sophie Alpert
Sophie Alpert

Reputation: 143194

React waits to mount all child components before calling componentDidMount on the parent. If you find a repro case where this isn't true, please file a bug.

Upvotes: 35

Related Questions