react native - Updating this.state.dataSource doesn't update ListView -
i have listview like:
<listview datasource={this.state.datasource} renderrow={this.rendermovie} style={styles.listview} />
it displays rows like:
<view style={styles.container}> <touchablehighlight onpress={this._onpressbutton.bind(this,movie)}> <image source={{uri: movie.uri}} style={styles.thumbnail} /> </touchablehighlight> <view style={styles.rightcontainer}> <text style={styles.title}>{movie.id}</text> <text style={styles.year}>{movie.votes}</text> </view> </view>
i have function updates this.state.datasource number of "votes" movie has. these changes aren't reflected in ui, when log this.state.datasource, changes there. need somehow re-render rows? shouldn't automatically change?
thanks!
to make react-native re-render rows, need create copy of array, update object, , use setstate newly created array. example:
let newarray = this.state.datasource.slice(); newarray[indextoupdate] = { ...this.state.datasource[indextoupdate], field: newvalue, }; this.setstate({ datasource: this.state.datasource.clonewithrows(newarray), });
reference:
Comments
Post a Comment