Next.js Discord

Discord Forum

Next map

Answered
Blue orchard bee posted this in #help-forum
Open in Discord
Blue orchard beeOP
Is this fine? bc is not working :

{links.map(({label,value})=>{
<Link className="navbar__link relative" href={value}>
a{label}
</Link>
})}
Answered by riský
you should add key to the unique link element: https://legacy.reactjs.org/docs/lists-and-keys.html#keys (and also follow the correct way of doing map - ie implicit return)
View full answer

13 Replies

Blue orchard beeOP
you should add key to the unique link element: https://legacy.reactjs.org/docs/lists-and-keys.html#keys (and also follow the correct way of doing map - ie implicit return)
Answer
Somali
You’re missing an explicit return, you’ll need it whenever you use the curly braces {}. Try this instead:

{links.map(({ label, value }) => (
  <Link className="navbar__link relative" href={value}> 
    {label}
  </Link>
))}
and slight formatting recommendation for both of you, you can style codeblocks
```jsx
export default function Component() {
return (
<h1>Hello 👋</h1>
)
}
```
turns into:
export default function Component() {
  return (
    <h1>Hello 👋</h1>
  )
}
Blue orchard beeOP
Thanks guys, now it works!
I have another question, how do i redirect a user on success of a function? like redirect("/")? bc is not working
you use nextjs's useRouter and .push
Blue orchard beeOP
Oh okay, i ll try that thanks
i meant the bot command (on message) btw - i know it isn't very normal tho
edit: i just did it