【发布时间】:2022-01-19 20:46:55
【问题描述】:
我使用useRef 来引用一个div 元素并存储getBoundingClientRect()。使用它时,我收到了 Property 'height' does not exist on type 'string' 的 TypeScript 错误。如何解决此错误?
const divRef = useRef(null);
const [divSize, setDivSize] = useState("0");
setDivSize(divRef.current.getBoundingClientRect());
console.log(divSize.height); // getting TS error: Property 'height' does not exist on type 'string'.
return (
<Content ref={divRef}>
{content}
</Content>
)
【问题讨论】:
标签: reactjs typescript use-ref