Why does this log an empty array [] (not supposed to be empty) in my console even though i get results via my API?
node js code:
app.get("/todos", async (req, res) => {
const todos = await todo.find()
res.json(todos)
})
react code:
const [todos, setTodos] = useState([])
useEffect(() => {
GetTodos()
console.log(todos);
}, [])
const GetTodos = () => {
fetch(API_BASE + "/todos")
.then(res => res.json())
.then(data => setTodos(data))
.catch((err) => console.error("Error: ", err));
}
All my endpoints seem to work with postman, i just can't figure out why react does't spit out the same result