Movatterモバイル変換


[0]ホーム

URL:


sveltejs-jotai
TypeScript icon, indicating that this package has built-in type declarations

0.0.5 • Public • Published

sveltejs-jotai

Primitive and flexible state management for Svelte based onJotai.

Experimental. Checkthis for more info.

Demo

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

Readme

Keywords

Package Sidebar

Install

npm i sveltejs-jotai

Weekly Downloads

2

Version

0.0.5

License

MIT

Unpacked Size

128 kB

Total Files

12

Last publish

Collaborators

  • hunghg255

[8]ページ先頭

©2009-2025 Movatter.jp