omcljs / om

ClojureScript interface to Facebook's React
6.66k stars 363 forks source link

om.next (dom/render-to-str (component initial-data)) throws ReactDOMServer undefined #837

Closed sova closed 7 years ago

sova commented 7 years ago

nf-starter-january.core=> (dom/render-to-str (blurb boo))

object[ReferenceError ReferenceError: ReactDOMServer is not defined]

ReferenceError: ReactDOMServer is not defined

[org.omcljs/om "1.0.0-alpha45"]

(it could just be an error on my part, but perhaps someone more experienced can take a look.)

anmonteiro commented 7 years ago

If you want to use om.dom/render-to-str on the CLJS side you need to include a deendency on ReactDOMServer in your project and require it. Om doesn't bundle ReactDOMServer since it's an optional feature which isn't very used.

sova commented 7 years ago

I want to use it is so I can render pages on the server-side in a server.clj file.

Is it possible to include the cljs dependency [cljsjs.react.dom.server] in a Clojure file?

Thanks

anmonteiro commented 7 years ago

If you're trying to use om.dom/render-to-str from Clojure you don't need a ReactDOMServer dependency. You certainly didn't get that error from Clojure, since what you pasted originally is a JavaScript error.

sova commented 7 years ago

You are right, that was a js error, not a clojure one.

I finally got it working, thank you so much for your help.

For any other newcomers, make sure that in your server.clj file you have

        [om.next :as om :refer [defui]]

in your :require statement.