VirtualizedList: You have a large list that is slow to update

前端 未结 4 1228
暖寄归人
暖寄归人 2020-12-05 02:10

I use FlatList with large number of items. I get following alert from Expo XDE.

VirtualizedList: You have a large list that is slow to update - make

4条回答
  •  悲&欢浪女
    2020-12-05 02:42

    I figured it out, why this bug is happened. The main problem is, when your onEndReached event is happened, im sure you are loading something from server, which means, you need to wait until your loading is finished from server, so after that you can call onEndReached event.

    But in your case there is multilple calling of onEndReached event. So when it happens, your application was trying to load datas from server again and again.

    Ok, how to solve this problem: you need to create new state, for example this is realization of infinite scrolling by pagination.

    const [loader, setLoader] = useState(false);
    
    const onEndReached = (page) => {
      if (next && !loader) {
        setPage(page + 1)
      }
    }
    
    const loadData = async () => {
      setLoader(true);
      const resp = await getData();
      setLoader(false);
    }
    
    
    

提交回复
热议问题