I'm am trying to .push
some data to my Firebase but I'm getting this error in my Chrome console:
Uncaught Error: Firebase.push failed: first argument contains an invalid key (cljs$lang$protocol_mask$partition0$) in property 'arr.0'. Keys must be non-empty strings and can't contain ".", "#", "$", "/", "[", or "]"
Here's my code:
fb (js/Firebase. "https://example.firebaseio.com/example-listings")
(def app-state (atom {"post" { :first_name "Billy"
:last_name "Bob"
:location "CA"
:email "[email protected]"
:website "www.pwt.com"
}}))
(def postData (get-in @app-state ["post"]))
(.push fb postData)
I also tried replacing the keys with strings :first_name
with "first_name"
. I understand Clojure's data structures are a bit different from JavaScript. Is it the case that Firebase isn't liking my Clojure map?
Firebase expects a JavaScript object to its API calls. You are passing it a Clojure data structure (in this case a map). You have to convert your Clojure data structure to a JavaScript object before passing it to the Firebase function.
So instead of:
(.push fb postData)
you need to do:
(.push fb (clj->js postData))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With