useSize在乾坤微前端做了多tab的keepAlive时候 子应用的 DOM 节点可能已经被销毁或重新挂载,导致 ResizeObserver 监听的节点失效 直接白屏 · Issue #2699 · alibaba/hooks · GitHub
More Web Proxy on the site http://driver.im/
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))
解决思路
import{useState,useEffect}from'react';exportconstuseSize=(domRef: React.RefObject<HTMLElement>)=>{const[size,setSize]=useState({width: 0,height: 0});useEffect(()=>{constelement=domRef.current;if(!element){console.warn('`useSize`: domRef is null or undefined.');return;}if(typeofResizeObserver==='undefined'){console.warn('`useSize`: ResizeObserver is not supported by this browser.');return;}letisMounted=true;// 防止卸载后更新状态constobserver=newResizeObserver(entries=>{if(!isMounted)return;try{constentry=entries[0];if(entry&&entry.target.isConnected){const{ width, height }=entry.contentRect;setSize({ width, height });}}catch(error){console.error('`useSize`: Error in ResizeObserver callback.',error);}});observer.observe(element);return()=>{isMounted=false;observer.disconnect();// 确保在卸载时断开监听};},[domRef]);returnsize;};
The text was updated successfully, but these errors were encountered:
报错信息:
TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))
解决思路
The text was updated successfully, but these errors were encountered: