[英]How to use Set with useRef?
我正在嘗試將Set
與useRef
一起使用。 這是我嘗試過的。
export default function App() {
const data = useRef<Set<string>>(new Set());
const add = () => {
data.current = new Set([...Array.from(data.current), "Add"]);
};
const show = () => {
console.log(data.current);
};
return (
<div className="App">
<button onClick={add}>Add</button>
<button onClick={show}>Show</button>
</div>
);
}
更新后檢查值時,我得到了Set {}
。 這里到底發生了什么?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.