Gathering detailed insights and metrics for jotai
Gathering detailed insights and metrics for jotai
Gathering detailed insights and metrics for jotai
Gathering detailed insights and metrics for jotai
👻 Primitive and flexible state management for React
npm install jotai
Typescript
Module System
Min. Node Version
Node Version
NPM Version
97.4
Supply Chain
96.8
Quality
85.8
Maintenance
100
Vulnerability
100
License
TypeScript (83.26%)
JavaScript (15.64%)
CSS (1.1%)
Total Downloads
120,842,138
Last Day
71,699
Last Week
1,777,105
Last Month
7,211,504
Last Year
64,930,419
MIT License
20,295 Stars
1,665 Commits
683 Forks
67 Watchers
6 Branches
263 Contributors
Updated on Aug 02, 2025
Latest Version
2.12.5
Package Id
jotai@2.12.5
Unpacked Size
488.40 kB
Size
85.27 kB
File Count
214
NPM Version
10.9.2
Node Version
22.15.0
Published on
May 27, 2025
Cumulative downloads
Total Downloads
Last Day
3.5%
71,699
Compared to previous day
Last Week
-2.2%
1,777,105
Compared to previous week
Last Month
1.6%
7,211,504
Compared to previous month
Last Year
72.6%
64,930,419
Compared to previous year
2
visit jotai.org or npm i jotai
Jotai scales from a simple useState replacement to an enterprise TypeScript application.
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.
1import { atom } from 'jotai' 2 3const countAtom = atom(0) 4const countryAtom = atom('Japan') 5const citiesAtom = atom(['Tokyo', 'Kyoto', 'Osaka']) 6const mangaAtom = atom({ 'Dragon Ball': 1984, 'One Piece': 1997, Naruto: 1999 })
It can be used like React.useState
:
1import { useAtom } from 'jotai' 2 3function Counter() { 4 const [count, setCount] = useAtom(countAtom) 5 return ( 6 <h1> 7 {count} 8 <button onClick={() => setCount((c) => c + 1)}>one up</button> 9 ...
A new read-only atom can be created from existing atoms by passing a read
function as the first argument. get
allows you to fetch the contextual value
of any atom.
1const doubledCountAtom = atom((get) => get(countAtom) * 2) 2 3function DoubleCounter() { 4 const [doubledCount] = useAtom(doubledCountAtom) 5 return <h2>{doubledCount}</h2> 6}
You can combine multiple atoms to create a derived atom.
1const count1 = atom(1) 2const count2 = atom(2) 3const count3 = atom(3) 4 5const sum = atom((get) => get(count1) + get(count2) + get(count3))
Or if you like fp patterns ...
1const atoms = [count1, count2, count3, ...otherAtoms] 2const sum = atom((get) => atoms.map(get).reduce((acc, count) => acc + count))
You can make the read function an async function too.
1const urlAtom = atom('https://json.host.com') 2const fetchUrlAtom = atom(async (get) => { 3 const response = await fetch(get(urlAtom)) 4 return await response.json() 5}) 6 7function Status() { 8 // Re-renders the component after urlAtom is changed and the async function above concludes 9 const [json] = useAtom(fetchUrlAtom) 10 ...
Specify a write function at the second argument. get
will return the current
value of an atom. set
will update the value of an atom.
1const decrementCountAtom = atom( 2 (get) => get(countAtom), 3 (get, set, _arg) => set(countAtom, get(countAtom) - 1) 4) 5 6function Counter() { 7 const [count, decrement] = useAtom(decrementCountAtom) 8 return ( 9 <h1> 10 {count} 11 <button onClick={decrement}>Decrease</button> 12 ...
Just do not define a read function.
1const multiplyCountAtom = atom(null, (get, set, by) => 2 set(countAtom, get(countAtom) * by), 3) 4 5function Controls() { 6 const [, multiply] = useAtom(multiplyCountAtom) 7 return <button onClick={() => multiply(3)}>triple</button> 8}
Just make the write function an async function and call set
when you're ready.
1const fetchCountAtom = atom( 2 (get) => get(countAtom), 3 async (_get, set, url) => { 4 const response = await fetch(url) 5 set(countAtom, (await response.json()).count) 6 } 7) 8 9function Controls() { 10 const [count, compute] = useAtom(fetchCountAtom) 11 return ( 12 <button onClick={() => compute('http://count.host.com')}>compute</button> 13 ...
Jotai's fluid interface is no accident — atoms are monads, just like promises! Monads are an established pattern for modular, pure, robust and understandable code which is optimized for change. Read more about Jotai and monads.
No vulnerabilities found.