I have several screens in my POS UI Extension and need to be able to pass a callback function to a screen that is being navigated to so the parent screen can receive data from the child screen.
Here’s the navigate method to navigate to another screen where I pass a callback function in the params object.
api.navigation.navigate('EnterGiftCodeScreen', {config, onCallback: () => console.log('callback invoked')});
Here’s the screen being navigated to:
<Screen name='EnterGiftCodeScreen' title='Enter Gift Code Manually' onReceiveParams={(params) => {
setParams(params);
params.onCallback();
}}>
...
</Screen>
When the params are received by the new screen and I try calling the callback function I get the following error on Android emulator:
Uncaught (in promise) Error: You attempted to call a function that was already released.
What is the best way to receive data back from a screen that is being navigated to?