Skip to content

Instantly share code, notes, and snippets.

@jeans11
Last active January 23, 2022 15:15
Show Gist options
  • Save jeans11/5a7ea1541401b412db7de868ef4e1851 to your computer and use it in GitHub Desktop.
Save jeans11/5a7ea1541401b412db7de868ef4e1851 to your computer and use it in GitHub Desktop.
Fulcro + React Native Web (without expo)
(ns demo.fulcro.rnw
"Set up Fulcro and React Native Web"
(:require ["react-native-web" :refer [AppRegister]])
(defsc Person [this {:person/keys [name age]}]
(dom/div
(dom/p "Name: " name)
(dom/p "Age: " age)))
(def ui-person (comp/factory Person))
(defsc Root [this props]
(dom/div
(dom/div "Hello!")
(ui-person {:person/name "Lucy" :person/age 29})))
(defn register-root-component! [app-name root-component fulcro-app]
(-> AppRegistry (.registerComponent app-name (fn [] (mroot/floating-root-react-class root-component fulcro-app)))))
(defn run-application! [app-name root-tag]
(-> AppRegistry (.runApplication app-name (clj->js {:rootTag (.getElementById js/document root-tag)}))))
(defn set-root! [app root-component]
(swap! (::app/state-atom app) #(merge {:fulcro.inspect.core/app-id (comp/component-name root-component)} %))
(app/set-root! app root-component {:initialize-state? true}))
(defn -mount-app []
(register-root-component! "App" Root)
(set-root! app Root)
(run-application! "App" "app"))
(-mount-app)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment