0

Only user my API fetch Network request failed use "https://api.douban.com/v2/movie/in_theaters" API is ok

react-native-cli: 1.0.0 react-native: 0.32.0

fetch('https://api.chooin.com/v1/product/index')
    .then((res) => alert(res))
    .then((data) => {
        // this.setState({
        //     loaded: true,
        //     products: this.state.products.cloneWithRows(data.subjects)
        // });
    })
    .done();
Devin
  • 3
  • 2

1 Answers1

0

You need to parse the first res into json

fetch('https://api.chooin.com/v1/product/index')
    .then(res => res.json())
    .then(data => {
        return this.setState({
            loaded: true,
            products: this.state.products.cloneWithRows(data.subjects)
        });
    })
    .catch(err => console.log(err));

Take a look here https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch

EQuimper
  • 4,734
  • 7
  • 24
  • 39