I’m migrating my Realtime database implementation from Namespaced to Modular. In Modular I have the following working correctly:
const reference = firebase.database().ref(`/projects/${uuid}`);
reference.off();
I have rewritten this to:
const reference = ref(firebase, `/projects/${uuid}`);
reference.off();
According to the docs, detaching listeners works the same (https://firebase.google.com/docs/database/web/read-and-write#detach_listeners). So I would expect reference.off() to still work, also in the modular version.
However, it gives the error:
Property ‘off’ does not exist on type ‘ DatabaseReference’.
What am I doing wrong?
>Solution :
As you can see from the API documentation for DatabaseReference, there are no methods at all on the object. That’s what the error message is telling you.
Instead, you can use the off() function. Be sure to read that carefully so you can match the event type with the one you used with whatever on*() function you used.
off(ref, 'your_matching_event_type');