如何在 React Native 中进行实时抓取?
How to do realtime fetching in react native?
您好,在我的项目中有一个 video.So 的评论部分,我希望在用户 post it.I 尝试 componentWillUpdate()
后立即显示评论] method.But 它每次都重新渲染 UI,所以在 UI.Also 中引起了一些震动 我试图在 [=13= 的承诺范围内调用 fetch
方法].这意味着在 posting 评论的提取中我试图调用下一个提取以显示提交的 comments.But 没有 use.Following 是我试过的代码
代码
postComment(){
fetch(GLOBAL.COMMENT + `${this.props.id}/new/0`, {
method: 'POST',
headers: {
'Authorization': token,
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
comment_content: this.state.text
})
})
.then((response) => response.json())
.then((responseData) => {
this.setState({
text: '',
isLoad: false
})
}).then(() => {
fetch(GLOBAL.GET_COMMENT + `${this.state.unit_id}/`, {
method: 'GET',
headers: {
'Authorization': token
}
}).then((response) => response.json())
.then((responseData) => {
this.setState({
comment: responseData.data,
tab2: true,
tab3: false,
isLoading: false
})
});
})
}
有什么解决办法吗?请help.Any帮助appreciated.Thank你!
所以它看起来像这样,我不确定您的其余代码是如何设置的,所以请稍加考虑。
getComments() {
fetch(GLOBAL.GET_COMMENT + `${this.state.unit_id}/`, {
method: 'GET',
headers: {
'Authorization': token
}
})
.then((response) => response.json())
.then((responseData) => {
this.setState({
comment: responseData.data,
tab2: true,
tab3: false,
isLoading: false
})
});
})
};
postComment() {
fetch(GLOBAL.COMMENT + `${this.props.id}/new/0`, {
method: 'POST',
headers: {
'Authorization': token,
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
comment_content: this.state.text
})
})
.then((response) => response.json())
.then((responseData) => {
this.getComments();
})
}
您好,在我的项目中有一个 video.So 的评论部分,我希望在用户 post it.I 尝试 componentWillUpdate()
后立即显示评论] method.But 它每次都重新渲染 UI,所以在 UI.Also 中引起了一些震动 我试图在 [=13= 的承诺范围内调用 fetch
方法].这意味着在 posting 评论的提取中我试图调用下一个提取以显示提交的 comments.But 没有 use.Following 是我试过的代码
代码
postComment(){
fetch(GLOBAL.COMMENT + `${this.props.id}/new/0`, {
method: 'POST',
headers: {
'Authorization': token,
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
comment_content: this.state.text
})
})
.then((response) => response.json())
.then((responseData) => {
this.setState({
text: '',
isLoad: false
})
}).then(() => {
fetch(GLOBAL.GET_COMMENT + `${this.state.unit_id}/`, {
method: 'GET',
headers: {
'Authorization': token
}
}).then((response) => response.json())
.then((responseData) => {
this.setState({
comment: responseData.data,
tab2: true,
tab3: false,
isLoading: false
})
});
})
}
有什么解决办法吗?请help.Any帮助appreciated.Thank你!
所以它看起来像这样,我不确定您的其余代码是如何设置的,所以请稍加考虑。
getComments() {
fetch(GLOBAL.GET_COMMENT + `${this.state.unit_id}/`, {
method: 'GET',
headers: {
'Authorization': token
}
})
.then((response) => response.json())
.then((responseData) => {
this.setState({
comment: responseData.data,
tab2: true,
tab3: false,
isLoading: false
})
});
})
};
postComment() {
fetch(GLOBAL.COMMENT + `${this.props.id}/new/0`, {
method: 'POST',
headers: {
'Authorization': token,
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
comment_content: this.state.text
})
})
.then((response) => response.json())
.then((responseData) => {
this.getComments();
})
}