选择器 returns 前一个值

Selector returns previous value

我有一个 redux-toolkit 切片,其 'loading' 状态值最初设置为 idle
调度 createAsyncThunk 操作时,loading 状态值更新为 pending,我可以从 Redux 开发工具观察到状态已正确更新。
分派在 useEffect 中调用,其值来自依赖项数组中的 loading 选择器。 在派发操作之前,我测试该值是否等于 'idle'。但不知何故,至少派发了两次动作(在我的代码中多次)。为什么?
选择器似乎没有接收到状态更改。

这是一个最小的可重现示例沙箱:https://codesandbox.io/s/hungry-sammet-0smieb

这是 StrictMode 组件的 behavior

useEffect(() => {
    if (loading === "idle") {
      console.count(loading);
      dispatch(getSomething());
    }
  }, [loading, dispatch]);

使用 StrictMode 组件,日志:

idle: 1 
idle: 2 

没有 StrictMode 组件,日志:

idle: 1 

Codesandbox

另见 Why is my React component is rendering twice?