I am using react js and using mongo db. i am trying to get data by fetch. but i get this type of error : Uncaught (in promise) SyntaxError: Unexpected end of JSON input
const [product, setProduct] = useState({});
useEffect(() => {
const url = `http://localhost:5000/product/${id}`;
fetch(url)
.then((res) => res.json())
.then((data) => setProduct(data));
}, [id]);
Your code in useEffect is correct the reason you may be getting this error is because of
you can confirm this by replacing res.json() with res.text() and then console.log it