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
| Name | Description | Type | Default |
|---|---|---|---|
| loading | Loading (set true before fetching, false when done) | boolean | false |
| finished | No more data (footer renders the locale text or finishedSlot) | boolean | false |
| error | Load failed (footer renders the retry entry) | boolean | false |
| offset | Distance to bottom that triggers the load (px) | number | 100 |
| immediateCheck | Run one bottom check right after mount | boolean | true |
| emptyText | Empty-state text (rendered when finished with no content) | string | — |
| ariaLabel | Accessible name | string | — |
| children | List content (plus's default slot) | ReactNode | — |
| loadingSlot | Loading indicator (default Spinner; plus's #loading slot) | ReactNode | — |
| finishedSlot | "No more" area (plus's #finished slot) | ReactNode | — |
| errorSlot | Error area (plus's #error slot) | ReactNode | — |
| emptySlot | Empty state (plus's #empty slot) | ReactNode | — |
| sx | Quick layout props | LhSxProps | — |
Events
| Name | Description | Type |
|---|---|---|
| onLoad | Reached the bottom (update loading / finished after fetching; plus's @load) | () => void |
| onErrorChange | Retry 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 fromariaLabel
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/emptySlotReactNode 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)