'React native check if event has been removed

I am adding KeyboardEvent listeners to my react native code, like so:

keyboardListener = Keyboard.addListener("keyboardDidShow", onKeyboardShowed);

There are several places when I call keyboardListener.remove() and I would like to be able to re-add this listener ONLY if it has been removed.

Something like this:

if(keyboardListener.isRemoved){
    // Reattach the listener
    keyboardListener = Keyboard.addListener("keyboardDidShow", onKeyboardShowed);
}

Is there a way to check keyboardListener.remove() has been called?



Solution 1:[1]

Well as of this post the removeListener() has been deprecated (https://reactnative.dev/docs/keyboard#removelistener). There is a .remove() which should be appended to addEventListener().

Solution 2:[2]

There is no function .remove(), you might mean removeListener or removeAllListeners like described in the Documentation?!?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 NathanNovak
Solution 2 suther