souce.uri не должен быть пустым - PullRequest
0 голосов
/ 01 октября 2019

Я получаю ошибку en после использования imgLink переменной состояния в методе рендеринга, что source.uri не должен быть пустым. пожалуйста, код ниже:

constructor(props)
 {
 super(props);
  this.state = {
 imgLink:'',
 }
 };

 onPressedButton = channelId =>
 {

  // fetch the value entered in the input field
  //alert(channelId);
 this.setState({channelId:channelId})
 //fetch the value(channelId) that is enter in the input field
 // make a request
 var url = 'https://www.googleapis.com/youtube/v3/channels? 
  key='+API_key+'&id=' + this.state.channelId + 
 '&part=snippet,contentDetails,statistics';
 this.setState({url: url});
 fetch(url,{
 method: 'GET'
 })
.then((response) =>
 response.json())
 // fetchData(data);
 .then((data) => {
  fetchData(data);
  alert('calling2');
  })
  //now fetching the response from the yt api again and again
  .setInterval(() =>
  {
  var url = 'https://www.googleapis.com/youtube/v3/channels? 
  key='+API_key+'&id=' + this.state.channelId + '&part=statistics';
  fetch(url,{
  method: 'GET'
  })
  .then((response) => updateSubscribers(response.json()))
  },0)

 .catch((error) => {
  console.log(error);
  });
  }      

 fetchData = data => {
 this.setState({imgLink: 
 data.items[0].snippet.thumbnails.default.url});
 }

Теперь в функции рендеринга я использую его как URI, но каждый раз, когда он говорит, что он пуст. Я не могу решить ее в течение нескольких дней, пожалуйста, решите ее и предложите несколько простых объяснений.

 render()
 {
  let{imgLink} = this.state
  <View style = {styles.container}>

  <ScrollView>
  <View style = {styles.results}>
  <Image style = {
   {width:width,height:height,alignItems:'center',borderRadius:50 
   ,marginLeft:'auto',marginRight: 'auto',marginTop: 30}
   } source = {{uri: imgLink}}/>
...