I'm trying to use React Hooks to update the state of an array.
Basically I have a list:
const hatList = ['🎩', '👒', '🎓', '🧢', '⛑', '🪖' ]
I want to loop through that list every time I do an onClick:
<Button
className="btn"
btnText="Show Me Missing Koroks!"
onClick={() => setHat(hatList[0 + 1])} // I know this gives me just the 2nd obj of the list, but how to loop through that list on every onClick ?
/>
This is the whole component:
const IndexPage = () => {
const [hat, setHat] = React.useState([])
const hatList = ['🎩', '👒', '🎓', '🧢', '⛑', '🪖' ]
return (
<main>
<header>
<h1>For the Love of BOTW</h1>
<h2>You thought you have found all the Koroks ?</h2>
</header>
<section>
<Button
className="btn"
btnText="Show Me Missing Koroks!"
onClick={() => setHat(hatList[0 + 1])}
/>
<>
<span role="img" aria-label='hat emoji various'>{hat}</span>
<Icon name="korok" />
<Icon name="mount" />
</>
</section>
</main>
)
}
export default IndexPage
How can I do this?