Tran Hoai Nam
Tran Hoai Nam

Reputation: 1363

React native log shows objects as "[object Object]"

I'm new to React native, I tried calling:

fetch('https://rallycoding.herokuapp.com/api/music_albums')
    .then((response) => response.json())
    .then((responseData) => {
      console.log(`TEST RESPONSE: ${responseData}`);
    });

to fetch the API and log it to debug. I expected to see the details of the result just like in the tutorial but instead, I got the output like:

TEST RESPONSE: [object Object],[object Object],[object Object],[object Object],[object Object]

It's supposed to be somehow like this, where I can expand the data to see the array: enter image description here

However, the result can be used and being populated into the list normally.

I am using

react-native-cli: 2.0.1

react-native: 0.56.0

What did I do wrong? Thank you for your time.

Upvotes: 0

Views: 909

Answers (1)

Poptocrack
Poptocrack

Reputation: 3009

You have to print it with console.log('TEST RESPONSE:', responseData)

Upvotes: 2

Related Questions