deno.land / x / jotai@v1.8.4 / website / src / demos / integrations.js

integrations.js
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { useAtom } from 'jotai';import { countAtom } from '../atoms';import { Button, Code } from '../components';
export const IntegrationsDemo = () => { const [count, setCount] = useAtom(countAtom);
const increment = () => setCount((c) => (c = c + 1));
const code = `import { useAtom } from 'jotai'import { atomWithImmer } from 'jotai/immer'
// Create a new atom with an immer-based write functionconst countAtom = atomWithImmer(0)
const Counter = () => { const [count] = useAtom(countAtom) return ( <div>count: {count}</div> )}
const Controls = () => { // setCount === update: (draft: Draft<Value>) => void const [, setCount] = useAtom(countAtom) const increment = () => setCount((c) => (c = c + 1)) return ( <button onClick={increment}>+1</button> )}`;
return ( <> <div className="flex items-center space-x-8 pt-4 lg:pt-8 lg:pb-4"> <Button onClick={increment} icon="plus" className="focus:ring"> Increment </Button> <span className="text-3xl font-bold ordinal slashed-zero tabular-nums">{count}</span> </div> <Code>{code}</Code> </> );};
jotai

Version Info

Tagged at
2 years ago