I'm trying to create a list of items where there are always 3 displayed per row and when i click on show more button another 3 will be displayed. Unfortunately I'm having trouble doing it using map and slice as using this approach always render 3 of the same items in one row and doesn't account for if the number of items is not dividable by 3. Any suggestions are welcomed
Here is what I have so far (the Math.random as a key is just a placeholder)
const renderRow = (
documentData: {
fileName: string;
description: string;
contentUrl: string;
}[],
) => {
return documentData.slice(0, limit).map((documentsRow, i) => {
return (
<Grid key={Math.random()} container spacing={1}>
<Grid container item xs={12} spacing={3}>
{renderRowItem(documentsRow)}
{renderRowItem(documentsRow)}
{renderRowItem(documentsRow)}
</Grid>
</Grid>
);
});
};
Here is a working sample - https://codesandbox.io/s/react-hooks-typescript-list-with-load-more-button-fvbue