我有下面的構造陣營本地:動態內容 - 渲染功能不更新視圖
constructor(props){
super(props);
this.renderConversations = this.renderConversations.bind(this);
this.startConversation = this.startConversation.bind(this);
this.state = {
conversationArray: []
}
在功能startConversation
我更新狀態變量。
startConversation(conversationObject) {
let currentResponse = conversationObject["responses"];
let thisResponse = currentResponse[Math.floor(Math.random() * currentResponse.length)];
this.state.conversationArray.push(thisResponse);
this.renderConversations();
}
在功能renderConversations
,我做了以下內容:
renderConversations(){
let conversationContent = this.state.conversationArray.map((conv, i) => {
return <View key={i} style={[globalStyle.conversationContainer,globalStyle.shadow]}><Text style= {globalStyle.conversationText}>{ conv }</Text></View>
})
return conversationContent
}
最後,在渲染功能,我渲染{this.renderConversations()}
。現在點擊按鈕觸發startConversation
。 但每次我更新狀態變量的組件不更新,我做錯了什麼?
正常工作。感謝您的額外提示。 :) –
很高興,它解決了你的問題:) –