All Projects → roman01la → hooks

roman01la / hooks

Licence: MIT License
React Hooks for ClojureScript

Programming Languages

clojure
4091 projects

hooks

React Hooks for ClojureScript

Installation

Add to deps.edn via Git deps

{hooks/hooks {:git/url "[email protected]:roman01la/hooks.git"
              :sha "1a98408280892da1abebde206b5ca2444aced1b3"}}

Install NPM deps

yarn add react react-dom [email protected] --save-dev

Hooks

hooks.core/use-atom

(defonce num (atom 0)) ;; or Reagent's RAtom or any other Atom-like datatype

(defn button []
  (let [v (hooks.core/use-atom num)]
    [:button {:on-click #(swap! num inc)}
     v]))

hooks.reagent/use-subscribe

(def use-subscribe
  (hooks.reagent/create-use-subscribe rf/subscribe))

;; Why `create-use-subscribe`?
;; because you may have your own, enhanced `subscribe`

(defn button []
  (let [v (use-subscribe [:app/num])]
    [:button {:on-click #(rf/dispatch [:num/inc])}
     v]))
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].