Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unnecessary calls startMapper/stopMapper in useAnimatedReaction #3864

Merged
merged 1 commit into from
Mar 31, 2023

Conversation

rozhkovs
Copy link
Contributor

Summary

Hey!
If we do not specify an array of dependencies in useAnimatedReaction and prepare or react has external dependent values (._closure), then the startMapper and stopMapper methods will be called an extra time on each render, even if the external values have not changed.

Test plan

If the functional component has such a block of code, then useEffect is called inside useAnimatedReaction on every render before these changes.

  const value = 1;
  useAnimatedReaction(
    () => value,
    () => {},
  );

@piaskowyk piaskowyk requested a review from kmagiera December 15, 2022 16:21
Copy link
Member

@kmagiera kmagiera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems ok, would only like to test this locally prior to merging

@kmagiera kmagiera added this pull request to the merge queue Mar 31, 2023
Merged via the queue into software-mansion:main with commit 4f48441 Mar 31, 2023
fluiddot pushed a commit to wordpress-mobile/react-native-reanimated that referenced this pull request Jun 5, 2023
…oftware-mansion#3864)

## Summary
Hey!
If we do not specify an array of dependencies in useAnimatedReaction and
prepare or react has external dependent values (._closure), then the
startMapper and stopMapper methods will be called an extra time on each
render, even if the external values have not changed.

## Test plan
If the functional component has such a block of code, then useEffect is
called inside useAnimatedReaction on every render before these changes.
```
  const value = 1;
  useAnimatedReaction(
    () => value,
    () => {},
  );
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants