Popover 内容动态更新后不重新渲染怎么办?
我在用 Ant Design 的 Popover 组件,内容是根据状态动态生成的,但状态变了 Popover 里的内容却没更新,还是旧的。明明 state 已经变了,控制台打印也对,就是 UI 不刷新。
我试过加 key 强制刷新,也试过把 content 写成函数,都不行。是不是我哪里写错了?
const [text, setText] = useState('初始内容');
const content = (
<div>
<p>{text}</p>
<button onClick={() => setText('已更新!')}>改内容</button>
</div>
);
return (
<Popover content={content} title="提示">
<Button>悬停看气泡</Button>
</Popover>
);
注意content现在是个箭头函数,每次都会重新渲染