我的工作任务需要帮助:我有一些具有以下样式的div块:
.main-div {
width: 500px;
height: 400px;
border: 1px solid #000;
resize: both;
overflow: hidden;
}
Run Code Online (Sandbox Code Playgroud)
还有一些 React 组件:
import React, { useState } from "react";
export const SomeComponent = () => {
const [width, setWidth] = useState();
const [height, setHeight] = useState();
return (
<div className="main-div">
<p>Block width: {width}, height: {height} </p>
</div>
)
}
Run Code Online (Sandbox Code Playgroud)
如何动态获取调整div大小的宽度/高度?我的意思是我必须在调整大小的过程中跟踪块尺寸。