I am new to reactJS, but thought I had understood the minimal change and update of DOM. Apparently I was wrong. I have a ReactJS-class Gallery, which renders a list of images (I included two functions of this class). The url of one image (in the images-list) is dependent on the Gallery state (index), so I thought that the image-url would change (forcing a new get request to the server), since it is dependent on the index-value of Gallery, by changing the gallery state.index to something else. How is my thinking incorrect? how can I update an image-url from the gallery class?
getInitialState: function(){
var self = this;
window.addEventListener('keypress', function(e){
if(e.keyCode == 39){
if(self.state.index < self.state.size){
self.setState({index: self.state.index+1});
console.log(self.state.index);
}
}
if(e.keyCode == 37){
if(self.state.index > 0){
self.setState({index: self.state.index-1});
console.log(self.state.index);
}
}
})
render:function(){
var images= [];
var url = "/patient/" + this.state.index.toString();
images.push(<Image src={url} width={500} height={520} left={150} top={this.state.base} />);
return (
<div>
{images}
</div>
);
}
might be a very relevant link (investigating now): Reactjs: how to modify child state or props from parent?