Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Detach listener realtime listener using modular SDK: "Property 'off' does not exist on type ' DatabaseReference'."

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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');
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading