Skip to content

Instantly share code, notes, and snippets.

@xpollen8
Created May 26, 2017 22:36
Show Gist options
  • Save xpollen8/cf031fabca5351e11fc4bfd5a00170fc to your computer and use it in GitHub Desktop.
Save xpollen8/cf031fabca5351e11fc4bfd5a00170fc to your computer and use it in GitHub Desktop.
nextjs/link - how to get 'item.id' to evaluate?
import Link from 'next/link';
export default () => (
<div>
Items
<ul>
{
[
{ name: 'item one', id: 1 },
{ name: 'item two', id: 2 },
].map( item =>
<li key={item.id}><Link href='/item?id={item.id}' as='/item/{item.id}'><a>{item.name}</a></Link></li>
)
}
</ul>
</div>
)
@xpollen8
Copy link
Author

When run via "next", those items outside of quotes are evaluated - {item.name} renders properly.

Those within quotes render literally as {item.id}.

What's the magic trick to force evaluation of object items w/in quotes?

@programbo
Copy link

programbo commented May 27, 2017

<li key={item.id}>
  <Link href={`/item?id=${item.id}`} as={`/item/${item.id}`}>
    <a>{item.name}</a>
  </Link>
</li>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment