I'm new to react. I've read through react documentation. I've no idea why it is not working. So, I come up here.
I'm trying to create pagination in react. Below is my table
component.
const Table = (props) => {
const { description, itemCount, tableHeaders, items } = props;
const pageSize = 5;
const [currentPage, setCurrentPage] = useState(1);
function handlePageChange(page) {
setCurrentPage(page);
}
const registerations = paginate(items, currentPage, pageSize);
// HERE: registerations data is correct and then I pass it to TableBody component.
return (
<React.Fragment>
<TableDescription description={description} count={itemCount} />
<div className="bg-white block w-full md:table">
<TableHeader items={tableHeaders} />
<TableBody items={registerations} />
</div>
{/* Footer & Pagination */}
<div className="bg-white block flex px-6 py-4 justify-between rounded-bl-lg rounded-br-lg">
<div className="sm:flex-1 sm:flex sm:items-center sm:justify-between">
<Pagination
itemsCount={items.length}
pageSize={pageSize}
currentPage={currentPage}
onPageChange={handlePageChange}
/>
</div>
</div>
{/* end Footer & Pagination */}
</React.Fragment>
);
and that registerations array is received by TableBody component. The problem here in TableBody component is that I can't set props value to state using useState hook.
const { items: passedItems } = props;
console.log(passedItems); // ok -> I got what I passed.
const [items, setItems] = useState(passedItems);
console.log(items); // not ok -> items is previously passed items.
How can I make it right? Thank You.