I use useState
like this and onclick event with name genreHandler:
const [clickedGenre, setClickedGenre] = useState<string>(null)
const genreHandler= (event: React.MouseEvent<HTMLLIElement>) => {
console.log(clickedGenre)
const li: HTMLLIElement = event.currentTarget;
setClickedGenre(li.id);
axios.get(API_URL+"products?category.genre="+clickedGenre)
.then((response) => {
setProductList( response.data );
})
.catch((error)=>{
console.log(error)
}),[clickedGenre]
}
here's my li tag
<li className="list-group-item text-uppercase"
key= {category.id} id={category.genre}
onClick={genreHandler}>{category.genre}</li>
When I click on li the usestate (clickedGenre) still null not change to {category.genre}. It's change on double click. Please help me, what's wrong with my code