Skip to content

Commit

Permalink
Jotai example
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Oct 16, 2024
1 parent c664ea6 commit 71a2ed6
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ playground/public/public/src/squint
!playground/viteconfig.mjs
out
.env
App.jsx
30 changes: 30 additions & 0 deletions examples/jotai/App.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
(ns App
#_:clj-kondo/ignore
(:require ["react" :as React])
(:require ["react-dom" :as rdom])
(:require ["jotai" :as jotai :refer [useAtom]]))

(def !anime (jotai/atom
[{:title "Ghost in the Shell"
:year 1995
:watched true}
{:title "Serial Experiments Lain"
:year 1998
:watched false}]))

(defn App []
(let [[anime setAnime] (useAtom !anime)]
#jsx [:div
[:ul
(for [item anime]
#jsx [:li {:key (:title item)}
(:title item)])]
[:button {:onClick #(setAnime (conj anime
{:title "Cowboy Bebop"
:year 1998
:watched false}))}
"Add Cowboy Bebop"]]))

(defonce elt (js/document.querySelector "#app"))

(rdom/render #jsx [App] elt)
5 changes: 5 additions & 0 deletions examples/jotai/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Jotai example

[Jotai](https://jotai.org/) is a primitive and flexible state management for React.

To run this example, run `npm install` and then `npm run dev`.
6 changes: 6 additions & 0 deletions examples/jotai/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<html>
<body>
<div id="app"></div>
<script type="module" src="./App.jsx"></script>
</body>
</html>
17 changes: 17 additions & 0 deletions examples/jotai/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"dependencies": {
"jotai": "^2.10.1",
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
"devDependencies": {
"concurrently": "^9.0.1",
"squint-cljs": "^0.8.117",
"vite": "^5.4.9"
},
"scripts": {
"vite:dev": "vite",
"squint:watch": "squint watch",
"dev": "concurrently \"npm run vite:dev\" \"npm run squint:watch\""
}
}
1 change: 1 addition & 0 deletions examples/jotai/squint.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{:paths ["."]}

0 comments on commit 71a2ed6

Please sign in to comment.