Hello i am wondering how can u guys run a function on every 5 seconds on React js
Here's the code:
function Home() { const [quotes,setQuotes] = useState([]) const getQuotes = ()=>{ axios.get('https://api.kanye.rest') .then(res=>{ const quotes = res.data.quote setQuotes(quotes) }) } useEffect(()=>{ getQuotes() },[]) return ( <div className="home-container"> <p className="pcolor">Here's a random quotes from Kanye:</p> <p>{quotes}</p> </div> )}
I am wondering how can u get the data every 5 seconds, so i it will automatically update in the jsx. And yeah, the kanye api are giving us a random quote everytime we request it.
https://stackoverflow.com/questions/65895606/how-to-run-a-function-and-change-the-content-every-5-seconds-on-reactjs January 26, 2021 at 11:44AM
没有评论:
发表评论