-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
useRecoilCallback() snapshot gets the latest state (#1610)
Summary: Pull Request resolved: facebookexperimental/Recoil#1610 NOTE: This is a breaking change, but the previous approach had a bug. Previously, `useRecoilCallback()` would attempt to provide a `Snapshot` based on the state that was currently rendered. However, there were some bugs where this was not the case. For example, a callback called from an effect handler may or may not have had the latest rendered state based on the timing of the setter. The new approach `useRecoilCallback()` will always try to get a snapshot with the latest state. This should also be more intuitive for users. Addresses #1604 Reviewed By: habond Differential Revision: D34236485 fbshipit-source-id: 0cb17cec40b50e8debeb57dc193b9f410d170fc5
- Loading branch information
Showing
8 changed files
with
95 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @emails oncall+recoil | ||
* @flow strict-local | ||
* @format | ||
*/ | ||
'use strict'; | ||
|
||
let _invalidateMemoizedSnapshot: ?() => void = null; | ||
|
||
function setInvalidateMemoizedSnapshot(invalidate: () => void): void { | ||
_invalidateMemoizedSnapshot = invalidate; | ||
} | ||
|
||
function invalidateMemoizedSnapshot(): void { | ||
_invalidateMemoizedSnapshot?.(); | ||
} | ||
|
||
module.exports = { | ||
setInvalidateMemoizedSnapshot, | ||
invalidateMemoizedSnapshot, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters