DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 963,274 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Cover image for response.json is not a function TypeError
Aishanii
Aishanii

Posted on

response.json is not a function TypeError

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)
       }
 }));
Enter fullscreen mode Exit fullscreen mode

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);
     });
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

DEV has this feature:

Settings

Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. πŸ›