I'm trying to generate a new quote when the button is clicked. Having trouble figuring out how to implement this. Googling around has led me to believe that the useCallback hook is the way to go, but I haven't any experience with it so I have yet to have any luck implementing it. Any help is appreciated! Thank you in advance.
/* eslint-disable react-hooks/rules-of-hooks */
import React, { useEffect, useState, useCallback } from 'react'
const Main = () => {
const [quote, setQuote] = useState(null)
const [author, setAuthor] = useState(null)
const [newQuote, setNewQuote] = useState(false)
useEffect(() => {
fetch('https://type.fit/api/quotes')
.then(response => response.json())
.then((data) => {
let randomIndex = Math.floor((Math.random() * data.length));
setQuote(data[randomIndex].text)
setAuthor(data[randomIndex].author)
})
.catch(err => console.error(err));
}, [])
return (
<div id='main' className='grid place-items-center h-screen w-screen text-center'>
{/* Quote Gen Container */}
<div className='flex flex-col justify-start mx-auto bg-sky-300 w-3/4 h-3/4 text-black space-y-3 p-32 rounded-3xl relative'>
<h1 className='text-bold text-3xl absolute top-0 mx-auto'>Random Quote Generator</h1>
<div>
<h4 id="text">{`"${quote}"`}</h4>
</div>
<div>
<p id="author">{`- ${author}`}</p>
</div>
<div id="button">
<button onClick={() => setNewQuote(null)} className='bg-black text-white rounded-xl p-2 abs'>New Quote</button>
</div>
</div>
</div>
)
}
export default Main