If I keep observe
inside setTimeout
then updateChild
called on 1st render, but if I removed setTimeout
then it works on every render. Could someone please help me how to solve this problem as I need the setTimeout
?
private observer = new MutationObserver(this.updateChild.bind(this));
updateChild(mutationsList: MutationRecord[], observer: MutationObserver) {
console.log('updated');
}
handelMouseEnter(){
if (this.popupTimer) {
clearTimeout(this.popupTimer);
}
this.popupTimer = setTimeout(() => {
this.container = document.createElement('div');
document.body.appendChild(this.container);
ReactDOM.render(
<Layout innerRef={e => (this.myRef = e)}>{this.props.children}</Layout>,
this.container,
);
if (this.myRef) {
this.observer.observe(this.myRef, { childList: true });
}
}, 500);
}