Error Blog
Hi Guys ,
This blog is about the error Uncaught (in promise) SyntaxError: Unexpected end of JSON input
Problem Statement
Unable to see the response from a http call in react js .
Error Details
error Log
ERROR DETAILS
Uncaught (in promise) SyntaxError: Unexpected end of JSON input
at <anonymous>:31:28
at <anonymous>:31:28
Solution
The http call does not return a json output . .
Code Changes
Please validate the API endpoint .
componentDidMount() {
}
fetch(`/api/users`)
.then(res => res.json())
.then(result => this.setState({ users: result.users }))
OUTPUT
Thanks for reading . Let me know your thoughts in the comments below .
No comments:
Post a Comment