I am trying to remove an event listener. The old way is deprecated. We are told to use .remove(). I am not sure how to refactor my code to do so. I am using a class component.
Can you provide an example of how to remove event listener. Currently my event listener is inside of another function. I have it that way as I may need to create another event listener every time the button is press and I need to remove the listener after the function runs.
startProcess = (result) => {
// stuff for running process
console.log("your function is running its process");
//deprecated but easy way to remove the event listener below
// eventEmitter.removeListener('PreparePaywallFinished', onPreparePaywallFinished);
//new way to remove event listen use remove() method on the EventSubscription returned by addEventListener()
this.subscribeStartProcess.remove;
};
handleBtnPress = () => {
// the listener
eventEmitter.addListener("onMidiStart", this.startProcess);
// emitter
NativeModules.midiBridgeStart(true, 2);
};
render(){
return <Button title='press' onPress={()=> handleBtnPress() />
}