-
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.
Retain snapshots for async callbacks (#1632)
Summary: Pull Request resolved: facebookexperimental/Recoil#1632 Automatically retains snapshots from `useRecoilCallback()` for the duration of async callbacks until the promise is resolved. This should help avoid potential user errors without needing to manually remember to `retain()` and release in a `finally` clause. Before: ``` const callback = useRecoilCallback(({snapshot}) => async () => { const release = snapshot.retain(); try { ... await ... use snapshot } finally { release(); } }); ``` After: ``` const callback = useRecoilCallback(({snapshot}) => async () => { ... await ... use snapshot }); ``` Manually retaining is still required if trying to persist the the Snapshot beyond the lifetime of the async callback or if it is used in async callbacks not dependent to a returned promise. Reviewed By: mondaychen Differential Revision: D34405832 fbshipit-source-id: daddc09a037c3f91b9790464adae7981191a16dd
- Loading branch information
1 parent
19aa2a3
commit 9f5b251
Showing
4 changed files
with
82 additions
and
11 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