Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
zxh0125 opened this issue Feb 20, 2023 · 5 comments
Closed

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

zxh0125 opened this issue Feb 20, 2023 · 5 comments
Labels
need reproduce We cannot reproduce your problem

Comments

@zxh0125
Copy link

zxh0125 commented Feb 20, 2023

Version of antd-mobile

5.28.0

Operating system and its version

Others

Browser and its version

微信

Sandbox to reproduce

No response

What happened?

/*

  • @author: nhsoft.zhangxh
  • @Date: 2023-02-06 10:27:27
  • @LastEditors: nhsoft.zhangxh
  • @LastEditTime: 2023-02-20 09:55:03
  • @description: 我的页面
    */
    import { InfiniteScroll, List } from 'antd-mobile'
    import { memo, useState } from 'react'
    import { sleep } from 'antd-mobile/es/utils/sleep'
    import { history } from 'umi'

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

@zxh0125 zxh0125 added the bug label Feb 20, 2023
@miracles1919
Copy link
Contributor

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

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

@miracles1919 miracles1919 added need reproduce We cannot reproduce your problem and removed bug labels Feb 21, 2023
@github-actions
Copy link
Contributor

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
Copy link

ycshill commented Aug 7, 2024

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

@ycshill
Copy link

ycshill commented Aug 7, 2024

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

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

你后来怎么解决的呢

@ycshill
Copy link

ycshill commented Aug 7, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need reproduce We cannot reproduce your problem
Projects
None yet
Development

No branches or pull requests

3 participants