Skip to content

Instantly share code, notes, and snippets.

@roman01la
Last active June 26, 2024 12:03
Show Gist options
  • Save roman01la/d1fb72ceb57e5a0200c87e8c59144a4b to your computer and use it in GitHub Desktop.
Save roman01la/d1fb72ceb57e5a0200c87e8c59144a4b to your computer and use it in GitHub Desktop.
(ns uix.ssr
(:require [uix.core :as uix :refer [$ defui]]
#?(:cljs ["react-slider" :as react.slider])
#?(:clj [uix.dom.server :as dom.server])))
#?(:cljs
(defui js-comp* [{:keys [children]}]
(let [[show? set-show] (uix/use-state false)]
(uix/use-effect
#(set-show true)
[])
(when show? children))))
#?(:clj
(defmacro js-comp [comp & args]
(when (uix.lib/cljs-env? &env)
`($ js-comp* ($ ~comp ~@args)))))
(defui app []
($ :<>
($ :h1 "Hello")
(js-comp react.slider/ReactSlider)))
#?(:clj
(dom.server/render-to-string ($ app)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment