I am new to react.I have trying to set the value using useState. But on first time it is not showing. But on next loading it shows the value.
import { useEffect, useState } from 'react';
const Home = () => {
const [trendingFood, setTrendingFood] = useState([]);
useEffect(() => {
fectedData();
}, [])
const fectedData = async() => {
const foodData =await fetch(`https://api.spoonacular.com/recipes/random?apiKey=${process.env.REACT_APP_TEMP_KEY}&number=10`);
const resp =await foodData.json();
setTrendingFood(resp);
console.log(resp)
console.log(trendingFood);
}
return <div>Home</div>
};
export default Home;