'VM839:1 Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0
I have used fetch api and listed but in my code it shows Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0 like this.In console i get data from api but i didn't get listed .This is my code ,
function Category(){
const [users, setUsers] = useState([]);
const fetchData = () => {
fetch(CategoryDataService.getAll())
.then(response => {
console.log(response);
return response.json()
})
.then(data => {
setUsers(data)
})
}
useEffect(() => {
fetchData()
}, [])
return(
<>
< Sidebar />
<h2 style={{textAlign:"center"}}>Category List</h2>
<div>
{users.length > 0 && (
<ul>
{users.map(user => (
<li key={user.id}>{user.category_name}</li>
))}
</ul>
)}
</div>
< Footer/>
</>
);
}
export default Category;
please check this. I am just a beginner to react so fix this error and explain this error and why this came?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
