I have a flatList view, I want it to scrollToEnd or scrollToIndex when the data has updated(fetch data from server), I do it in comoponentDidUpdate but it doesn't work.Now when the render is completed, the listView always scrolls to top and I cann't see the latest loaded data.So is there a way to capture the event when the render is completed.
code:
...
fetchData(){
fetch(url)
.then((res)=>{
this.setData({data:[...this.state.data, res.data]})
})
}
componentDidUpdate(){
this.refs.listView.scrollToEnd({animated:true})
}
render(){
return <FlatList ref='listView' data={this.state.data} onEndReached={()=>this.fetchData()}.../>
}