I am getting an deprecated error when using the follow code for removing event listener. When I try to use it anyway nothing happens. Can someone help me fix the code block so that I remove the event listen correctly. I am using this in a functional component
remove
eventEmitter.removeListener("PreparePaywallFinished", onPreparePaywallFinished);
add listener
eventEmitter.addListener("PreparePaywallFinished", onPreparePaywallFinished);
Here is same of the code I am working with
// raise paywall by event listener then clear listener after paywall is raised
const onPreparePaywallFinished = result => {
if (result.success == true) {
NativeModules.NamiPaywallManagerBridge.raisePaywall();
} else {
console.log('error is ' + result.errorMessage);
}
eventEmitter.addListener('PreparePaywallFinished', onPreparePaywallFinished)
};
// create event listener on button press. also emit event
const _handlePress = () => {
console.log('pressed');
const subscription = eventEmitter.addListener('PreparePaywallFinished', onPreparePaywallFinished); //prettier-ignore
NativeModules.NamiPaywallManagerBridge.preparePaywallForDisplay(true, 2); //prettier-ignore
};
// button to be pressed
return(
<View>
<Button title="press me" onPress={() => press()} />
</View>
)
According to Native documents, this has been deprecated and not used. You can use .remove()