deno.land / x / jotai@v1.8.4 / docs / api / babel.mdx

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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
---title: Babeldescription: This doc describes the `jotai/babel` bundle.nav: 2.04---
## plugin-debug-label
Jotai is based on object references and not keys (like Recoil). This means there's no identifier for atoms. To identify atoms, it's possible to add a `debugLabel` to an atom, which can be found in React devtools.
However, this can quickly become cumbersome to add a `debugLabel` to every atom.
This `babel` plugin adds a `debugLabel` to every atom, based on its identifier.
The plugin transforms this code:
```jsexport const countAtom = atom(0)```
Into:
```jsexport const countAtom = atom(0)countAtom.debugLabel = 'countAtom'```
Default exports are also handled, based on the file naming:
```js// countAtom.tsexport default atom(0)```
Which transform into:
```js// countAtom.tsconst countAtom = atom(0)countAtom.debugLabel = 'countAtom'export default countAtom```
## Usage
With a `babel` configuration file:
```json{ "plugins": ["jotai/babel/plugin-debug-label"]}```
Examples can be found below.
## plugin-react-refresh
This plugin adds support for React Refresh for Jotai atoms. This makes sure that state isn't reset, when developing using React Refresh.
## Usage
With a `babel` configuration file:
```json{ "plugins": ["jotai/babel/plugin-react-refresh"]}```
Examples can be found below.
## preset
Jotai ships with a `babel` containing the plugins created for Jotai.
## Usage
With a `babel` configuration file:
```json{ "presets": ["jotai/babel/preset"]}```
## Examples
### Next.js
<CodeSandbox id="o2di2" />### Parcel
<CodeSandbox id="bgf3b" />
jotai

Version Info

Tagged at
a year ago