下拉加载刷新

注意传参没有pageNo的话,就不能实现下拉刷新,因为不知道当前要加载哪页的内容

const [list, setList] = useState();
const [showLoading, setShowLoading] = useState(false);
  const memoState = useMemo<{
    pageNo: number;
    total: number;
    cacheList: ModelList[];
  }>(() => {
    return {
      pageNo: 1,
      total: 0,
      cacheList: []
    }
  }, []);
    const fetchList = useCallback(
    debounce(async (nextPage = false) => {
      // 没有更多数据了
      if (nextPage && memoState.cacheList.length >= memoState.total) {
        return;
      }
      setShowLoading(true);
      try {
        const newPageNo = memoState.pageNo + 1;
        const res = await getListUser({
          lotteryId: Number(getQueryParam('detailId')) || Number(getQueryParam('wyswyg')),
          pageNo: nextPage ? newPageNo : 1,
          pageSize: 20,
          mockFile: 'getListUser'
        })
        setShowLoading(false);
        if (!res?.data) {
          return;
        }
        // !nextPage && setShowList(true);
        memoState.pageNo = res.data.joinedUsers.pageNo;
        memoState.total = res.data.joinedUsers.totalCount;
        memoState.cacheList = res.data.joinedUsers.pageNo === 1 ? res.data.joinedUsers.modelList : [...memoState.cacheList, ...res.data.joinedUsers.modelList];

        setList({
          ...res.data,
          joinedUsers: {
            ...res.data.joinedUsers,
            modelList: [...memoState.cacheList]
          }
        })
        
      } catch (e) {
        setShowLoading(false);
        console.error(e);
      }

    }, 10), [list]);
    
  const loadNextPage = useCallback(() => {
    fetchList(true);
  },[showLoading, fetchList])


}
  


//ParticipantList/index.tsx
 
    {modelList.map((item, index) => { return (
  • {item.userNick}
    {i18n.partJoinShow.replace(//g, item.joinTimeDisplay)}
  • ) })}

你可能感兴趣的:(数学建模,java,python)