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: