【发布时间】:2019-06-14 19:11:57
【问题描述】:
componentDidMount () {
this.showPosts();
}
showPosts = async () => {
var userID = await AsyncStorage.getItem('userID');
fetch(strings.baseUri+"getPostWithUserID", {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"user_id": userID
})
})
.then((response) => response.json())
.then((responseJson) => {
this.setState({show: false}); // If I comment this line, then I don't get the warning.
})
.catch((error) => {
console.error(error);
});
}
如何使用 componentWillUnmount,因为我收到以下警告。 当我使用 componentWillUnmount 时,有没有办法可以将 setState 显示为 true? Warning
【问题讨论】:
-
@Andrew 如果您能在我的场景中给出答案,是否有可能?我无法理解如何使用您提供的链接中给出的内容。 TIA :)
标签: reactjs react-native