Open this example in the interactive library
Live preview
Source code
// components/LoadMoreList.tsx
import { useState } from "react";
export default function LoadMoreList({
items = ["Oak", "Pine", "Maple"],
}: { items?: string[] } = {}) {
const [limit, set] = useState(2);
return (
<section>
<ul>
{items.slice(0, limit).map((v, i) => (
<li key={i}>{v}</li>
))}
</ul>
{limit < items.length && (
<button onClick={() => set((n) => n + 2)}>Show more</button>
)}
</section>
);
}
