javascriptreactjsredux-thunkfacebook-redex

redux-thunk fetch parse response


I am new to redux and reactjs and I am trying to fetch some server side data to my code.

This is my thunk fetch:

fetch(`/WebApp/Dashboard/CreateAlert`).then(response => {
    console.log(response);
});

This is what I see in the console:

enter image description here

In fiddler I see the response is "Success" as expected.

Is this response valid and how do I parse it, I am a bit confused and there is very little info online.

EDIT:

I changed to:

fetch(url).
then(response => response.json())
.then(json => {
    console.log(json);
});

And I received the object. Now when I send a complex type(List), I see the bellow:

enter image description here


Solution

  • If you want to parse a json response:

    fetch(`/WebApp/Dashboard/CreateAlert`)
        .then(response => response.json())
        .then(json => {
            console.log(json);
        });
    

    See https://developer.mozilla.org/en-US/docs/Web/API/Body for all of the methods you can use to parse the response body.