xxxxxxxxxx
import React, { useState } from 'react';
function App() {
const [items, setItems] = useState([1, 2, 3, 4, 5]);
const [visibleItems, setVisibleItems] = useState(3);
const loadMore = () => {
setVisibleItems(visibleItems + 3);
};
return (
<div>
{items.slice(0, visibleItems).map((item) => (
<div key={item}>{item}</div>
))}
{visibleItems < items.length && (
<button onClick={loadMore}>Load More</button>
)}
</div>
);
}
export default App;