If you are using fetch
The fetch() method returns a Promise that response to a Response object. The json() method basically parses the response for JSON which is then changed to a native JavaScript object.
Use the json method on response
with correct call to fetch.
useEffect(() => {
fetch("https://jsonplaceholder.typicode.com/todos")
.then((response) => response.json())
.then((data) => {
console.log(data)
}
}));
If you are using axios
Axios keeps parsing the response in check, so we just look into the data
property of response as it contains the data sent from the server.
import axios from 'axios';
useEffect(() => {
axios.get("https://jsonplaceholder.typicode.com/todos")
.then((response) => {
const ex = response.data.json();
console.log(ex);
});
}
Top comments (0)