-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add previous result to useAnimatedReaction (#1653)
## Description In some cases, we don't want to run the `reaction` callback from `useAnimatedReaction` if the value received from the `preparing` callback doesn't change. This equality could be checked always and calling the `reaction` callback would be then conditional. However, it's better to leave the decision to the user as there are as well cases when we still want to run the `reaction` even if its argument doesn't change. To solve the problem, keeping backward compatibility, the value of the previous call of the `preparing` callback is now being passed to the `reaction`. Besides the cases that were mentioned here, it lets users perform more custom operations. ## Code example ```Js const x = useSharedValue(0); const flag = useSharedValue(false); useAnimatedReaction( () => { return x.value > 125 && flag.value; }, (data, previous) => { if (data !== previous) { // only if it changes, perform some actions } } ); ``` ## Checklist - [x] Included code example that can be used to test this change - [x] Updated TS types - [x] Added TS types tests - [x] Added unit / integration tests - [x] Updated documentation - [x] Ensured that CI passes
- Loading branch information
1 parent
0b5cb09
commit fd5c6ad
Showing
5 changed files
with
47 additions
and
7 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
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