The syntax of useState
hook is straightforward.
const [value, setValue] = useState(defaultValue)
If you are not familiar with this syntax, go here.
I would recommend you reading the documentation.There are excellent explanations with decent amount of examples.
import { useState } from 'react';_x000D_
_x000D_
function Example() {_x000D_
// Declare a new state variable, which we'll call "count"_x000D_
const [count, setCount] = useState(0);_x000D_
_x000D_
// its up to you how you do it_x000D_
const buttonClickHandler = e => {_x000D_
// increment_x000D_
// setCount(count + 1)_x000D_
_x000D_
// decrement_x000D_
// setCount(count -1)_x000D_
_x000D_
// anything_x000D_
// setCount(0)_x000D_
}_x000D_
_x000D_
_x000D_
return (_x000D_
<div>_x000D_
<p>You clicked {count} times</p>_x000D_
<button onClick={buttonClickHandler}>_x000D_
Click me_x000D_
</button>_x000D_
</div>_x000D_
);_x000D_
}
_x000D_