sir_gray
7 سال پیش توسط sir_gray مطرح شد
1 پاسخ

ریکت نیتیو دریافت نشدن اطلاعا از api

سلام ...
من یه چندتا برنامه نوشتم که یه سری api دریافت میکرد و نمایش میداد ولی الان دیگه هیچی دریافت نمیشه ...
اومدم دوباره یه تست زدم دیدم کلا از هیچ api چیزی دریافت نمیشه ...

import React, { Component } from 'react';
import { View, Text } from 'react-native';

class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      data: null,
    };
  }
  componentWillMount() {
    console.log('ok');
    this.fromApi()
    console.log(this.state.data)
  }

  render() {
    let movies = this.state.data.map((val, key) => {
      return <View key={key} >
        <Text>{val.title}</Text>
      </View>
    })
    return (
      <View>
        {movies}
      </View>
    );
  }
  fromApi() {
    return fetch('https://facebook.github.io/react-native/movies.json')
      .then((response) => response.json())
      .then((responseJson) => {
        this.setState({
          data: responseJson.movies
        })
      })
      .catch((e) => {
        console.log(e);
      })
  }
}

export default App;