ant-design / ant-design-mobile

Essential UI blocks for building mobile web apps.
https://mobile.ant.design
MIT License
11.59k stars 2.39k forks source link

InfiniteScroll loadMore 初始化调用两次接口 #5983

Closed zxh0125 closed 1 year ago

zxh0125 commented 1 year ago

Version of antd-mobile

5.28.0

Operating system and its version

Others

Browser and its version

微信

Sandbox to reproduce

No response

What happened?

/*

import styles from './index.less' import ListItem from './ListItem'

import { getOrders } from '@/services/order' import type { ISaveOrderRes } from '@/types/sale/sumbitOrder'

let count = 0

export async function mockRequest() { if (count >= 5) { return [] } await sleep(2000) count++ return [ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', ] }

export default memo(function Me() { const offset = 0 const limit = 4

const [hasMore, setHasMore] = useState(true)

// const [offset, setOffset] = useState(0) // const [limit, setLimit] = useState(10)

const [orderData, setOrderData] = useState<ISaveOrderRes[]>([])

// const getOrders=()=>{

// }

const loadMore = async () => { count++

const res = await getOrders({
  limit: count * limit,
  offset: count * offset
})
if (res.isSuccess()) {
  setOrderData(p => [...p, ...res.data])
}
setHasMore(res?.data?.length > 0)

}

const goDetail = (id: string) => { history.push(/purchasedetail/${id}) } return (

<div className={styles.me_content}>
  <div className={styles.me_content_list}>
    <List>
      {orderData?.map((item) => (
        <List.Item key={item.id}>
          <div onClick={() => goDetail(item.id)}>
            <ListItem orderInfo={item} />
          </div>
        </List.Item>
      ))}
    </List>
    <InfiniteScroll loadMore={loadMore} hasMore={hasMore} /> 
  </div>
</div>

) })

Relevant log output

No response

miracles1919 commented 1 year ago

有可能是第一次调用 loadMore 后,高度还是不够,所以调用了第二次

具体的可以来个复现 demo, codesandbox or stackblitz.

github-actions[bot] commented 1 year ago

Hi, zxh0125.

Please provide a online reproduction so that we can help you troubleshoot the problem. You can create a demo by codesandbox or stackblitz.

我们需要你提供一个在线的重现实例,以便于我们帮你排查问题。你可以通过 codesandboxstackblitz 创建一个实例。

ycshill commented 3 weeks ago

我也有同样的问题,不是调用两次啊,如果高度不够一致调,可怎么处理

ycshill commented 3 weeks ago

有可能是第一次调用 loadMore 后,高度还是不够,所以调用了第二次

具体的可以来个复现 demo, codesandbox or stackblitz.

你后来怎么解决的呢

ycshill commented 3 weeks ago

Hi, zxh0125.

Please provide a online reproduction so that we can help you troubleshoot the problem. You can create a demo by codesandbox or stackblitz.

我们需要你提供一个在线的重现实例,以便于我们帮你排查问题。你可以通过 codesandboxstackblitz 创建一个实例。

把你们官网的demo1, setData([1]).就复现了,因为一直触发源码中的useEffect