Javascript 等待动态内容在react中填充dom
我试图检测列表何时已完全填充了项目,以便可以滚动到React中的特定项目 我曾尝试使用setTimeout和requestAnimationFrame来延迟执行,但两者似乎都有问题。。。 UseEffectHook也不起作用,因为它在实际重新绘制dom之前运行 以下是我到目前为止的情况:Javascript 等待动态内容在react中填充dom,javascript,reactjs,dom,react-dom,mutation-observers,Javascript,Reactjs,Dom,React Dom,Mutation Observers,我试图检测列表何时已完全填充了项目,以便可以滚动到React中的特定项目 我曾尝试使用setTimeout和requestAnimationFrame来延迟执行,但两者似乎都有问题。。。 UseEffectHook也不起作用,因为它在实际重新绘制dom之前运行 以下是我到目前为止的情况: const observer = new MutationObserver(mutationList => { console.log(mutationList); if (listR
const observer = new MutationObserver(mutationList => {
console.log(mutationList);
if (listRef.current) {
if (listRef.current?.contains(searchedItemRef.current)) {
console.log('Found Node');
console.log(searchedItemRef.current);
searchedItemRef.current!.scrollIntoView({ block: 'center' });
}
}
});
useEffect(() => {
if (listRef.current)
observer.observe(listRef.current, {
childList: true,
subtree: true,
});
}, [props.activeChatChannel]); //some global state that represents chat data