Check if all Child-Components have been mounted

懵懂的女人 提交于 2020-01-12 14:08:08

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/23734862/check-if-all-child-components-have-been-mounted

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!