The call is successful but dosent return anything.
Server:
export const getTopMovies = async (req, res) => {
console.log("Inside Server")
res.status = 200
res.data = "movies";
return res;
> }
Client:
import { useEffect } from 'react';
const topMovies = () => {
//const [movies, setMovies] = useState();
useEffect(() => {
fetch('http://localhost:8000/movies/getTopMovies')
.then(response => response.json())
.then(data => console.log(data.data))
}, [])
return (
<div className="max-h-screen w-full fixed h-screen bg-BGColor pt-6">
<h1 className="text-zinc-50 pt-4 pl-10 text-2xl ">Top Movies</h1>
<div className="min-w-[82.5%] absolute min-h-[78%] mt-6 ml-10 rounded-3xl bg-BGColorLight1 text-white">
</div>
</div>
)
}
export default topMovies
I tried to return a simple string and log the response but didn’t work.
2
Answers
You should return the
response.json()
Your
getTopMovies
controller doesn’t respond with anything.You should use the methods from the
res
object:status
method with200
as the argument.json
method to send thedata: "movies"
.Modify your
getTopMovies
into: