facebookexperimental/Recoil

useRecoilCallback batched set calls update state incorrectly

Open

#1,935 建立於 2022年8月5日

在 GitHub 查看
 (14 留言) (0 反應) (0 負責人)JavaScript (19,428 star) (1,151 fork)batch import
bughelp wanted

描述

We've been using Recoil quite extensively and believe we have encountered a bug with useRecoilCallback and state updating.

There is a rootState atom that we want to update via a useRecoilCallback that contains multiple set calls. If the set calls within useRecoilCallback try to set the recoil state of rootState directly or through a single selector layer, the final rootState is as expected. However, if there is more than one layer of selector dependencies, it is only the last set that has a result on rootState.

Here is the CodeSandbox.

Expected: All steps change their state from ['1', '2', '3'] to ['one', 'two', 'three'] Result: The only step changing the state is the last one for which set has run. In effect: ['1', '2', '3'] changes to ['1', '2', 'three']

貢獻者指南