reactjs – My fetched data return as undefined, how do I fix this?
I have this markup and code on my page:
import { useState, useEffect } from 'react';
import './Sidebar.css'
import TagsList from './TagsList';
const Sidebar = () => {
const [tags, setTags] = useState([]);
useEffect(()=>{
fetch('http://localhost:8000/tags')
.then(res=>{
res.json();
})
.then(data =>{
console.log(data);
})
}, [])
return (
);
}
export default Sidebar;
For some reason, when I try to fetch my data, the browser returns "undefined". Does anyone have a fix to this? Thank you so much
Read more here: Source link
