use-state.tsx
00import { useState } from "react"
01
02export function LikeCounter() {
03 const [likes, setLikes] = useState(0)
04 return <>
05 <div>{likes}</div>
06 <button onClick={ () => setLikes(likes + 1) }>Like</button>
07 <button onClick={ () => setLikes(0) }>Reset</button>
08 </>
09}
localhost:3000
0
useState
Used to create a reactive state variable and a function to update it.