【发布时间】:2020-12-08 22:02:10
【问题描述】:
https://codesandbox.io/s/charming-ives-3jnnn
根据链接的代码框,我有一个条形图,可以计算一个月内来自 4 个不同传感器的轨迹。我遵循了本教程:https://github.com/muratkemaldar/using-react-hooks-with-d3/tree/15-stacked-bar-chart,效果很好。现在我已经将很多代码转换为使用 mobx,但我正在努力让它工作。我让它使用 useState 但它似乎一直想刷新。 如何编码“onChange”部分?
onChange={(e) => {
if (e.target.checked) {
setKeys(Array.from(new Set([...keys, key])));
} else {
setKeys(keys.filter((_key) => _key !== key));
}
【问题讨论】: