Skip to main content

List

Infinite scroll list with load-on-bottom: the bottom detection (scrollTop + clientHeight ≥ scrollHeight - offset) and the state machine (idle → loading → finished / error) are fully consumed from @lh-ui/share/core/list; the nearest scrollable ancestor is detected automatically (falls back to window), throttled to one check per frame with rAF. The loading indicator reuses the Spinner component; the error footer retry writes back via onErrorChange(false) and re-fires onLoad.

Basic usage​

Load on bottom (with failure retry)

Loaded 0 items — scroll to bottom to load more (simulated pagination)

import { useCallback, useState } from 'react'
import { LhList } from '@lh-ui/react'

export default function Demo() {
const [items, setItems] = useState<number[]>([])
const [loading, setLoading] = useState(false)
const [finished, setFinished] = useState(false)
const [error, setError] = useState(false)

const fetchPage = useCallback(() => {
setLoading(true)
setTimeout(() => {
setLoading(false)
setError(false)
setItems((prev) => {
const next = Array.from({ length: 8 }, (_, i) => prev.length + i + 1)
if (prev.length + next.length >= 20) setFinished(true)
return [...prev, ...next]
})
}, 600)
}, [])

return (
<div style={{ maxHeight: 240, overflowY: 'auto' }}>
<LhList
loading={loading}
finished={finished}
error={error}
emptyText="No orders yet"
onLoad={fetchPage}
onErrorChange={setError}
>
{items.map((item) => (
<div key={item} style={{ padding: '10px 0' }}>{`Order ${item}`}</div>
))}
</LhList>
</div>
)
}

List API​

Props​

NameDescriptionTypeDefault
loadingLoading (set true before fetching, false when done)booleanfalse
finishedNo more data (footer renders the locale text or finishedSlot)booleanfalse
errorLoad failed (footer renders the retry entry)booleanfalse
offsetDistance to bottom that triggers the load (px)number100
immediateCheckRun one bottom check right after mountbooleantrue
emptyTextEmpty-state text (rendered when finished with no content)string—
ariaLabelAccessible namestring—
childrenList content (plus's default slot)ReactNode—
loadingSlotLoading indicator (default Spinner; plus's #loading slot)ReactNode—
finishedSlot"No more" area (plus's #finished slot)ReactNode—
errorSlotError area (plus's #error slot)ReactNode—
emptySlotEmpty state (plus's #empty slot)ReactNode—
sxQuick layout propsLhSxProps—

Events​

NameDescriptionType
onLoadReached the bottom (update loading / finished after fetching; plus's @load)() => void
onErrorChangeRetry click write-back (clears the controlled error; plus's @update:error)(value: boolean) => void

Accessibility​

  • The root element reflects loading via aria-busy; the accessible name comes from ariaLabel

Form differences across platforms​

  • plus / vue2: scroll container listening (nearest scrollable ancestor auto-detected), named slots available
  • React: named slots map to loadingSlot / finishedSlot / errorSlot / emptySlot ReactNode props (loading / finished / error are boolean props, suffixed with Slot to avoid naming conflicts)
  • uniapp / wxapp / alipay: degraded to the scroll-view scrolltolower (see each platform's docs)