Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 257
Philip Giuliani Avatar asked May 19 '14 10:05

Philip Giuliani


1 Answers

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.

like image 136
Sophie Alpert Avatar answered Oct 24 '22 04:10

Sophie Alpert