no-use-state.tsx
-> 0
00import { useState } from "react"
01
02export function LikeCounter() {
03 const [str, setStr] = useState('-')
04 const liked = 0
05 return <>
06 <div>{ str }</div>
07 <div>{ liked } Likes</div>
08 <button onClick={ () => setStr(getRandomString()) }>
09 Randomize
10 </button>
11 <button onClick={ () => liked += 1 }>Like</button>
12 </>
13}
localhost:3000
-
0 Likes
Rerenders reset normal variables.
1x