question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Animation withCallback, Value is undefined, expected an Object

See original GitHub issue

Description

I need to have a callBack after the animation ends But when I add withCallback, I have error modal Value is undefined, expected an Object

const animationEnd = SlideOutRight.withCallback((finished: boolean) => {
// other code
});

{!shouldAnimate && (
   <Animated.View entering={SlideInLeft} exiting={animationEnd}>
      <View />
    </Animated.View>
)}

Expected behavior

a callBack after animation ends

Actual behavior & steps to reproduce

After state changes, animation starts and then error modal if withCallback was selected

Screenshot 2022-01-21 at 15 42 21

Package versions

name version
react-native 0.64.3
react-native-reanimated ~2.3.1
NodeJS v14.18.0
expo 44

Affected platforms

  • Android
  • iOS
  • Web

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

9reactions
fristyrcommented, Jan 24, 2022

Oh, it was because I wasn’t enough attentive… So instead of the solution above, I did next

const animationEnd = SlideOutRight.withCallback((finished: boolean) => {
    'worklet';
    if (finished) { 
       // Wrong
       runOnJs(myCallback() <- //here was my problem  )() 
       // Correct
       runOnJs(myCallback)() 
    }
});
6reactions
jquartzcommented, Jan 23, 2022

@fristyr I had this issue and solved it by declaring the callback function as a worklet then running my JS code with the runOnJS function

const animationEnd = SlideOutRight.withCallback((finished: boolean) => {
    'worklet';
    if (finished) { 
       runOnJs(myCallback)() 
    }
});

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Native render error Value is undefined expected a object
Update your react-native-reanimated version.In my case I have react-native-reanimated version 2.3.1 and rolling back to 2.2.4 version.
Read more >
Exiting Animations | React Native Reanimated
In React Native during unmounting of components from the hierarchy of views, it just disappears in the next frame. However you can beautify...
Read more >
Conditional JavaScript Callbacks with Reanimated in React ...
In order to communicate back you need to use call which is a declared method that you provide a list of animated values...
Read more >
React native - Can't dispatch action in component because ...
[Solved]-React native - Can't dispatch action in component because state gets undefined-React Native. Search. score:0. boards: state.boards.filter ((it) ...
Read more >
Promise - The Modern JavaScript Tutorial
A promise is a special JavaScript object that links the “producing ... initially undefined , then changes to value when resolve(value) is ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found