Search code examples
clojurescriptomreagent

Use a different React version with clojurescript react libraries (reagent,om,rum,quiescent)


How can I use a different React version with Reagent, Om, Rum, Quiescent or Brutha?


Solution

  • Self answer since this is asked frequently:

    First you have to tell Leiningen to exclude the cljsjs/react dependencies:

    [rum "0.6.0" :exclusions [[cljsjs/react] [cljsjs/react-dom]]]
    

    If you have other dependencies pulling in cljsjs/react you can use a global exclusion:

    :exclusions [[cljsjs/react] [cljsjs/react-dom]]
    

    Next you have to satisfy the compiler since it won't find the namespaces cljsjs.react and cljsjs.react.dom. For this create two files that hold these namespaces in your source directory. For instance

    - src/cljsjs/react.cljs
    - src/cljsjs/react/dom.cljs
    

    Both only need the namespace declaration and can otherwise be empty (ns cljsjs.react).

    Now you can include any React version you'd like manually in your HTML file with a normal <script> tag.

    Alternative:

    You can also use foreign-libs compiler option.