如何计算元素在 redux 反应中获得焦点的时间

How to count the time an element has focus in redux react

我有一个 React 组件,如果它的焦点持续 2 秒,我想执行一个动作。在纯粹的反应中,我有内部状态可以处理这个。 使用 Redux 的正确方法是什么?

Use React for ephemeral state that doesn't matter to the app globally and doesn't mutate in complex ways. For example, a toggle in some UI element, a form input state. Use Redux for state that matters globally or is mutated in complex ways. For example, cached users, or a post draft.

Sometimes you'll want to move from Redux state to React state (when storing something in Redux gets awkward) or the other way around (when more components need to have access to some state that used to be local).

The rule of thumb is: do whatever is less awkward.

https://github.com/reactjs/redux/issues/1287

这是 Dan Abramov Redux 创建者的回答。

在你的情况下,我认为使用 React 组件状态是可以的。