Next.js Discord

Discord Forum

Displaying only a specific amount of content

Answered
ihyd posted this in #help-forum
Open in Discord
Let's say I have an example of a few cards that are associated with an account, like this:

function getCards() {
    return {
        main: {
            amount: "2,500,727.69"
        },
        loyalty: {
            amount: "727"
        },
        usd: {
            amount: "100,000"
        },
        euro: {
            amount: "100,000"
        },
        secondary: {
            amount: "100,000"
        }
    }
}


I want to display let's say only 3 at the same time, and have a left arrow and right arrow that lets me cycle between them, how would I go about implementing this? I'm thinking of using something like mapping:

                <section className="flex flex-row p-4 gap-4 border-b-2 w-[70%] overflow-scroll rounded">
                    <button className="text-black material-symbols-outlined text-[30px]">arrow_back</button>
                        {Cards.map((card, index) => (
                            <MainCard key={index} amount={card.main.amount} />))}
                    <button className="text-black material-symbols-outlined text-[30px]">arrow_forward</button>
                </section>
            


but I don't know if that would work for this, any ideas?
Answered by ihyd
i'll try to work with that
View full answer

13 Replies

I already have a Main Card element and loyalty card element which should be in position 1 and 2
but everything else should appear after, if it exists, and then cycle between them smoothly
for the sake of this, consider there's an element called Card that has an amount and currency prop
fair enough haha thank you very much i'll look into it ^^
i never really understood shadcn but i guess now's the time
Not exactly necessary to use shadcn, can use any carousel-related libraries or code that you can find
The keyword is “carousel” and just search for it, there are tons of results
@joulev The keyword is “carousel” and just search for it, there are tons of results
I understand carousels and I did look around but none of them seemed to fit what I needed, but shadcn seems perfect
i'll try to work with that
Answer
works almost perfectly.. very wonky but, it does the job
thank you :)