📌  相关文章
📜  窗口调整下一个 js - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:28.303000             🧑  作者: Mango

代码示例1
const useWidth = () => {
    const [width, setWidth] = useState(0); // default width, detect on server.
    const handleResize = () => setWidth(window.innerWidth);
    useEffect(() => {
      window.addEventListener('resize', handleResize);
      return () => window.removeEventListener('resize', handleResize);
    }, [handleResize]);
    return width;
};