sveltejs-jotai
0.0.5 • Public • Publishedsveltejs-jotai
Primitive and flexible state management for Svelte based onJotai.
Experimental. Checkthis for more info.
Demo
Installation
pnpm add jotai sveltejs-jotai
Usage
import{atom}from'sveltejs-jotai';exportconstcountAtom=atom(0);
<scriptlang="ts">import{useAtom}from'sveltejs-jotai'import{countAtom}from'./atoms'constcount=useAtom(countAtom)</script><buttonon:click={() => count.update(prev => prev + 1)}> Clicks: {$count}</button>
Atom
An atom represents a piece of state. All you need is to specify an initial value, which can be primitive values like strings and numbers, objects and arrays. You can create as many primitive atoms as you want.
import{atom}from'sveltejs-jotai';constcountAtom=atom(0);constcountryAtom=atom('Japan');constcitiesAtom=atom(['Tokyo','Kyoto','Osaka']);constmangaAtom=atom({'Dragon Ball':1984,'One Piece':1997,Naruto:1999});// Derived atomsconstdoubledCountAtom=atom((get)=>get(countAtom)*2);constsum=atom((get)=>get(countAtom)+get(doubledCountAtom));// Async atomsconstasyncAtom=atom(async()=>'hello');
Read more aboutJotai here.
License
MIT
Package Sidebar
Install
npm i sveltejs-jotai
Repository
Weekly Downloads
2
Version
0.0.5
License
MIT
Unpacked Size
128 kB
Total Files
12