【发布时间】:2019-09-28 19:06:22
【问题描述】:
我在 onPressed 上导入一个函数,但每次我按下图标时都会出现错误:“未定义不是 setInterval 附近的函数”。请解决。
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);
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);
});
}
我从中导入的文件:
<Icon style = {styles.icon}
name = 'search'
type = 'material'
color= 'black'
onPress = {() => {
this.setState({channelId: this.getChannelId(this.state.term)});
obj.onPressedButton(this.state.channelId);
}
}
/>
【问题讨论】:
标签: ecmascript-6 react-native-android