When I click on a new li tag, I want the classname to change to active (which works), but also remove active from the rest of the li tags (which doesn't work). document.getElementByTagName('li').classList.remove="active", doesn't work because it is saying it is not defined. Should I go about this a different way... maybe storing something different in the state?
import React, {useState, useEffect} from 'react';
import './Anime.css';
function Anime(){
const [currentCase, setCurrentCase] = useState(0)
function getAnime(){
fetch('https://kitsu.io/api/edge/anime')
.then(response => response.json())
.then(data => console.log(data));
}
function currentSelector(e){
document.getElementsByTagName('li').clasList.remove("active");
setCurrentCase(e.target.value)
e.target.className = "active"
}
useEffect(() => {
getAnime();
}, []);
return(
<div className="anime">
{/* Selectors */}
<ul>
<li value= {0} className="active" onClick={currentSelector}>Trending</li>
<li value={1} onClick={currentSelector}>Action</li>
<li value={2} onClick={currentSelector}>Adventure</li>
<li value={3} onClick={currentSelector}>Comedy</li>
<li value={4} onClick={currentSelector}>Drama</li>
<li value={5} onClick={currentSelector}>Magic</li>
<li value={6} onClick={currentSelector}>Romance</li>
</ul>
</div>
)
}
export default Anime
clasListshould have 2 "s"s. Please compare in the code snippet you provided. Additionally, why are you using the regular DOM API instead of dealing with this in React's APIs?