问题
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