LoadMore
Adds the next part of a list under the one on screen. When everything is shown it says so instead.
import { LoadMore } from '@sypnia/ui/react'
On this page
A feed of events
- Event 1
- Event 2
- Event 3
- … 20 events on screen
Code
import { useState } from 'react';
import { LoadMore } from '@sypnia/ui/react';
// Each press adds the next part under the list; at the end it says everything is shown.
export default function Feed() {
const [shown, setShown] = useState(20);
const [busy, setBusy] = useState(false);
const total = 47;
return (
<div className="sy-stack">
<ol className="sy-text--muted">{Array.from({ length: Math.min(shown, 3) }, (_, i) => <li key={i}>Event {i + 1}</li>)}<li>… {shown} events on screen</li></ol>
<LoadMore count={Math.min(20, total - shown)} shown={shown} hasMore={shown < total} busy={busy}
onLoad={() => { setBusy(true); setTimeout(() => { setShown(Math.min(total, shown + 20)); setBusy(false); }, 700); }} />
</div>
);
} When to use it
Use it when
- Feeds and short lists where people read from the top.
- Say how many come next: «Show 20 more».
Do not use it when
- Tables people compare or come back to: use Pagination so each page has an address.
For everyone
- The button works while loading and does not add twice.
- The end of the list is said in words.
Props
| LoadMore | Type | Default |
|---|---|---|
countrequiredHow many the next part brings. | number | |
hasMorerequired | boolean | |
onLoadrequired | () => void | |
shownrequiredHow many are on screen, for the closing line. | number | |
busy | boolean |