我無法理解這段代碼中的問題: export default function CustomPopup({wi,he,children}) { //some code const [popupSize,setPopupSize] = useState([`${wi}px`,`${he}px`]) const handlePopupSize = () =>{ let c = []; (window.innerWidth < (wi/0.9)) ? c[0] = `90%` : c[0] = `${wi}px`; (window.innerHeight < (he/0.8)) ? c[1] = `80%` : c[1] = `${he}px`; if (c != popupSize) { setPopupSize(c) }; } window.addEventListener("resize", handlePopupSize) return ( <div className="popup--page--wrapper"> <div className="popup--box" style={{width: popupSize[0], height: popupSize[1]}}> { children } </div> </div> ) }當我調整頁面大小時,頁面會嚴重滯后,甚至導致瀏覽器出現錯誤。代碼似乎有問題,但我無法找出。提前致謝!
React useState 表現非常糟糕
互換的青春
2023-09-14 20:46:04