Skip to content
Advertisement

How to call push() function from firebase database

I’m trying to get a unique key from the push function but whenever I call it I get this error: Uncaught TypeError: postsRef.push is not a function at HTMLFormElement. These are my imports:

JavaScript

And these are the lines that I use to call the push function:

JavaScript

I hope you guys can help me, thank you

Advertisement

Answer

push is nowadays a top-level function, and no longer a method in a reference.

Since you’re already importing push, you can use it as:

JavaScript

The change is very mechanical here: changing from object.operation() to operation(object), which is a common pattern when moving over from older Firebase SDK to v9 and above.

Advertisement