when I use componentWillMount to load data,and invoke setState,the onEndReached call twice,the expected result is Zero!why I set the state can effect it?
async componentWillMount(){
var onInitLoadData=this.props.onInitLoadData;
var refreshData;
if(onInitLoadData){
refreshData=await onInitLoadData();
}
if(!refreshData){
refreshData=[];
}
refreshData=refreshData;
if(refreshData.length>200){//only 200 datas
refreshData=refreshData.slice(refreshData.length-200,refreshData.length)
}
if(refreshData.length>0) {
this.setState({
isRefreshing: false,
datas: refreshData,
dataSource: initDatasource.cloneWithRows(refreshData),
currentPage:0
});
}else{
this.setState({
isRefreshing: false,
datas: refreshData,
currentPage:1
});
}
}
2016-04-23 01:18:32.292 [info][tid:com.facebook.react.JavaScript] _onEndReached=================call====================
2016-04-23 01:18:32.307 [info][tid:com.facebook.react.JavaScript] _onEndReached=================call====================
Keep in mind that your componentWillMount function is async (not in general, but in your example). That means initially ListView will be rendered with no rows (empty) and if you e.g. attempt to scroll it or interact with it in anyway, it will trigger the onEndReached callback.
Second time that's called is when you render with data loaded but the amount of rows is smaller than what can fit on screen, which means the end was automatically reached.
If you have any further questions regarding that behaviour, feel free to open StackOverflow question and CC me. It's generally a good practice to post questions there instead as thanks to its voting system you are more likely to get the answer faster!
@facebook-github-bot answered
Closing this issue as @satya164 says the question asked has been answered. Please help us by asking questions on StackOverflow. StackOverflow is amazing for Q&A: it has a reputation system, voting, the ability to mark a question as answered. Because of the reputation system it is likely the community will see and answer your question there. This also helps us use the GitHub bug tracker for bugs only.
See also #6782
Most helpful comment
Keep in mind that your
componentWillMountfunction is async (not in general, but in your example). That means initially ListView will be rendered with no rows (empty) and if you e.g. attempt to scroll it or interact with it in anyway, it will trigger theonEndReachedcallback.Second time that's called is when you render with data loaded but the amount of rows is smaller than what can fit on screen, which means the end was automatically reached.
If you have any further questions regarding that behaviour, feel free to open StackOverflow question and CC me. It's generally a good practice to post questions there instead as thanks to its voting system you are more likely to get the answer faster!