Reactjs 检查是否已安装所有子组件

Reactjs 检查是否已安装所有子组件,reactjs,react-jsx,Reactjs,React Jsx,是否有任何方法可以检测儿童是否已安装?初始化同位素时,必须为初始化安装所有子组件。它的超时时间为5毫秒,工作正常,但我相信有更好的方法 componentDidMount: function() { var container = this.refs.vinesOverview.getDOMNode(); setTimeout(function() { var isotope = new Isotope(container, { itemSelect

是否有任何方法可以检测儿童是否已安装?初始化同位素时,必须为初始化安装所有子组件。它的超时时间为5毫秒,工作正常,但我相信有更好的方法

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);
}
更新

我现在试过这个:

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);
  },

5毫秒后,它计算出了高度?这就是同位素不起作用的原因。这是一个错误还是正常?谢谢

React在父组件上调用
componentDidMount
之前,会等待装入所有子组件。如果您发现一个与此不符的复制案例,请提交一个bug。

您好,谢谢您的回答!我已经用我发现的一些东西更新了我的问题。确定布局何时发生并不是React可以控制的事情。我猜您的代码还受到其他一些因素的影响——当调用componentDidMount时,React完全是在触及DOM时完成的(ReactTransitionGroup这样的特殊情况除外,在这种情况下,另一个更新会进入队列),因此,它被直接初始化。当调用父级的
componentDidMount
方法时,可能会装入所有子级组件,但在子级的
componentDidMount
之前会调用父级的
componentDidMount
。我应该提交一个bug吗?和JulienD一样,在调用内部componentDidMount之前调用父componentDidMount