Код: Выделить всё
useEffect(() => {
const fetchPosts = async () => {
setIsLoading(true);
try {
const response = await axios.get(`${process.env.REACT_APP_BASE_URL}/posts`);
console.log("API Response:", response); // Log the API response
setPosts(response?.data);
} catch (err) {
console.log("Error fetching posts:", err); // Log any errors
}
setIsLoading(false);
};
fetchPosts();
}, []);
Подробнее здесь: https://stackoverflow.com/questions/782 ... ked-by-orb
Мобильная версия