I have the following constructor
constructor(props){
super(props);
this.renderConversations = this.renderConversations.bind(this);
this.startConversation = this.startConversation.bind(this);
this.state = {
conversationArray: []
}
}
In function startConversation
I update the state variable.
startConversation(conversationObject) {
let currentResponse = conversationObject["responses"];
let thisResponse = currentResponse[Math.floor(Math.random() * currentResponse.length)];
this.state.conversationArray.push(thisResponse);
this.renderConversations();
}
In the function renderConversations
, I'm doing the following:
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
}
Finally, in the render function, I render {this.renderConversations()}
. Now startConversation
is triggered on a button click.
But each time I update the state variable the component is not updated, What am I doing wrong?