Skip to content

Commit e062002

Browse files
committed
docs: update usage
1 parent d08f3eb commit e062002

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

README.md

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,54 @@
44
55
[![Test](https://github.com/barelyhuman/babel-transform-mutable-react-state/actions/workflows/test.yml/badge.svg)](https://github.com/barelyhuman/babel-transform-mutable-react-state/actions/workflows/test.yml)
66

7+
**UNSTABLE**
8+
**The plugin is still under development so isn't recommended for production**
9+
710
## Install
811

912
TBD
1013

1114
## Usage
1215

13-
**UNSTABLE**
14-
The plugin is still under development so isn't recommended for production
16+
You write state with a prefix `$` and that's converted to `useState` accordingly.
17+
18+
```jsx
19+
import * as React from 'react'
20+
21+
function Component() {
22+
let $a = 1
23+
24+
const onPress = () => {
25+
$a += 1
26+
}
27+
28+
return (
29+
<div>
30+
<p>{$a}</p>
31+
<button onClick={onPress}>Press</button>
32+
</div>
33+
)
34+
}
35+
```
36+
37+
```jsx
38+
import * as React from 'react'
39+
40+
function Component() {
41+
const [a, setA] = React.useState(1)
42+
43+
const onPress = () => {
44+
setA(a + 1)
45+
}
46+
47+
return (
48+
<div>
49+
<p>{a}</p>
50+
<button onClick={onPress}>Press</button>
51+
</div>
52+
)
53+
}
54+
```
1555

1656
## License
1757

0 commit comments

Comments
 (0)