Last active
June 12, 2018 06:41
-
-
Save reedho/f6898e2b34a00c220dc154dfc29a3cc5 to your computer and use it in GitHub Desktop.
Basic React with Clojurescript :npm-deps (without cljsjs/react) -- React 16.x workaround
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Note: | |
Due to React 16.x react-dom/index conditionally load actual | |
react-dom implementation based on NODE_ENV, | |
we have to set it to "production" to make it works. | |
Note: | |
For advanced build, we include cljsjs/react* (just) to make use | |
its provided externs. | |
Files involved: | |
1. cljsc.edn | |
2. deps.edn | |
3. src/example/core.cljs | |
For development, start repl with: | |
$ clj -m cljs.main -co cljsc.edn -c -r | |
For simple build, build with: | |
$ clojure -m cljs.main -co cljsc.edn -O simple -c | |
For advanced build: | |
$ clojure -A:advanced-build -m cljs.main -co cljsc.edn -O advanced -c | |
;+++ cljsc.edn +++ | |
{:main example.core, | |
:npm-deps {:react "16.4.0" | |
:react-dom "16.4.0"} | |
:install-deps true | |
:process-shim true | |
:closure-defines {process.env/NODE_ENV "production"} | |
:verbose true} | |
;+++ deps.edn +++ | |
{:deps {org.clojure/clojurescript {:mvn/version "1.10.238"}} | |
:aliases | |
{:advanced-build | |
{:extra-deps | |
{cljsjs/react {:mvn/version "16.4.0-0"} | |
cljsjs/react-dom {:mvn/version "16.4.0-0"}}}}} | |
;+++ src/example/core.cljs +++ | |
(ns example.core | |
(:require [react] | |
[react-dom] | |
["react-dom/server" :as rds])) | |
(defn create-element [c opts & children] | |
(apply react/createElement c (clj->js opts) children)) | |
(console.log | |
(rds/renderToString | |
(create-element "h1" {} "Hello you there"))) | |
(react-dom/render | |
(create-element "h1" {} "Hello you there...") | |
(.getElementById js/document "app")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment