counter.tsxbefore
1import { useState } from "react"
2
3function Counter() {
4−const count = 0
5 const [items, setItems] = useState([])
6
7 return (
8 <div>
9− <p>Count: {count}</p>
10 <button onClick={() => setItems([])}>
11 Reset
12 </button>
13 </div>
14 )
15}
counter.tsxafter
1import { useState } from "react"
2
3function Counter() {
4+const [count, setCount] = useState(0)
5 const [items, setItems] = useState([])
6
7 return (
8 <div>
9+ <p>Count: {count}</p>
10 <button onClick={() => setCount(c => c + 1)}>
11 Increment
12 </button>
13 </div>
14 )
15}
VS