Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/roman01la/hooks
React Hooks for ClojureScript
https://github.com/roman01la/hooks
Last synced: 2 days ago
JSON representation
React Hooks for ClojureScript
- Host: GitHub
- URL: https://github.com/roman01la/hooks
- Owner: roman01la
- License: mit
- Created: 2021-11-26T20:54:30.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2021-11-30T22:29:43.000Z (almost 3 years ago)
- Last Synced: 2024-08-03T13:04:49.221Z (3 months ago)
- Language: Clojure
- Size: 8.79 KB
- Stars: 22
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hooks
React Hooks for ClojureScript## Installation
### Add to `deps.edn` via Git deps
```clojure
{hooks/hooks {:git/url "[email protected]:roman01la/hooks.git"
:sha "1a98408280892da1abebde206b5ca2444aced1b3"}}
```
### Install NPM deps
```shell
yarn add react react-dom [email protected] --save-dev
```## Hooks
### `hooks.core/use-atom`
```clojure
(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`
```clojure
(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]))
```