Next.js Discord

Discord Forum

need help with Listboxitem from nextUI

Unanswered
Argentine hake posted this in #help-forum
Open in Discord
Argentine hakeOP
In the following code, cities is an array containing city names. These names aren't necessarily unique. When I map through it, I need to provide key prop to the returned JSX code. So its producing erro here since keys aren't unique. But i can't provide any other as key here, because Listboxitem takes key as its value

4 Replies

Argentine hakeOP
<Listbox
                                    onAction={(key) =>
                                        setSelectedCity(key as string)
                                    }>
                                    {cities.map((city) => (
                                        <ListboxItem
                                            key={city}
                                            color="primary"
                                            className="text-primary-500">
                                            {city}
                                        </ListboxItem>

                                    ))}
                                </Listbox>
here is listbox code from nextui/orgr
how do I fix this? please help
Argentine hakeOP
if you need extra explanation for understanding the problem, then please let me know