pitch-io / uix

Idiomatic ClojureScript interface to modern React.js
https://github.com/pitch-io/uix?tab=readme-ov-file#docs
Eclipse Public License 2.0
359 stars 21 forks source link
clojure clojurescript react

Idiomatic ClojureScript interface to modern React.js

"Oh god, I just started learning reagent. Don’t tell me I’ll have to switch" /r/clojure

CircleCI Clojars Project Clojars Project

Installation

yarn add react@18.3.1 react-dom@18.3.1
{:deps {com.pitch/uix.core {:mvn/version "1.1.1"}
        com.pitch/uix.dom {:mvn/version "1.1.1"}}}

How to start a new project with UIx

Usage

(ns my.app
  (:require [uix.core :refer [defui $]]
            [uix.dom]))

(defui button [{:keys [on-click children]}]
  ($ :button.btn {:on-click on-click}
    children))

(defui app []
  (let [[state set-state!] (uix.core/use-state 0)]
    ($ :<>
      ($ button {:on-click #(set-state! dec)} "-")
      ($ :span state)
      ($ button {:on-click #(set-state! inc)} "+"))))

(defonce root
  (uix.dom/create-root (js/document.getElementById "root")))

(uix.dom/render-root ($ app) root)

Docs

Testing

scripts/test

Note: to ensure you're using the right Node.js version, you can use nvm and run nvm use once in the directory. Otherwise the Node.js version you use is in the .nvmrc file. See nvm repo for more documentation.

Publishing

  1. Update version in core/release.edn, dom/release.edn and in README.md
  2. Update docs if needed
  3. Update CHANGELOG.md
  4. Publish both core and dom packages to Clojars
cd core && CLOJARS_PASSWORD={YOUR_CLOJARS_TOKEN} clj -A:release --skip-tag
cd dom && CLOJARS_PASSWORD={YOUR_CLOJARS_TOKEN} clj -A:release --skip-tag

Who's using UIx?

Thanks to