Well you asked a React/Javascript programming issue. Not really a Twitch API issue.
Your Axios code seems wrong.
const axios = require('axios');
axios.defaults.headers.common["Client-ID"] = 'CLIENT';
axios
.get("https://api.twitch.tv/helix/streams?user_login=blaschikovsky")
.then(response => {
console.log(response.data);
console.log(response.data.length);
if (response.data.length !== 0) {
console.log('Is not zero');
} else {
console.log('Is Zero');
}
})
.catch(error => {
console.log(error);
});
results in:
{ data: [], pagination: {} }
undefined
Is not zero
The use of !== performs a test and a type cast test. So you’ve tried to see if an OBJECT has length. And of course an object doesn’t
Line 12:
this.setState({data: response.data})
Should be:
this.setState({data: response.data.data})
Response.data fetches the response from twitch, but you probably want the data array in the respone that’ll contain 0/1 streams in an array which is what you can test the length of as it’s an Array.