1

我正在重写 Recharts 的工具提示功能,以在页面的其他位置(在另一个组件中)提供悬停数据。

<Tooltip content={ this.showTooltipData.bind(this) } />

showToolTipData 触发了一个动作创建器,它修改了当前渲染方法敏感的状态树的一部分,但我仍然收到可怕的反模式警告:

Warning: setState(...): Cannot update during an existing state transition (such as within `render` or another component's constructor). Render methods should be a pure function of props and state; constructor side-effects are an anti-pattern, but can be moved to `componentWillMount`.

此警告既正确又不正确,因为渲染组件不受状态更改的影响。我关心这一点的唯一原因是警告可能会向控制台发送垃圾邮件(有 1000 个点中的 10 个悬停在上面)。

有一个更好的方法吗?我考虑过使用目标悬停数据组件的“私有”状态(与现在使用的 redux 状态相反),但我在其他地方也需要该数据。将功能移至componentWillMount()是不可能的。

有人找到了一种更安全的方法来覆盖 ToolTip 函数吗?

4

1 回答 1

0

怪异的蟋蟀。一旦我有时间,我会把它交给redux......

于 2017-05-04T11:37:31.087 回答