react: fix incorrect use of keys

Signed-off-by: Paul W. <lambdapaul@protonmail.com>
This commit is contained in:
Paul W. 2024-12-06 13:52:40 -05:00
parent 4f25a3bc3d
commit ff03bd50ff
Signed by: lambda
GPG Key ID: 0D207B4EBC14B1BD
7 changed files with 80 additions and 80 deletions

View File

@ -5,11 +5,11 @@ function QuickLinks() {
return ( return (
<div className='block'> <div className='block'>
{ {
Object.entries(Pages).map(([title, link], i) => { Object.entries(Pages).map(([title, link]) => {
const extern = link.match(/^http/) && `blue extern` || ''; const extern = link.match(/^http/) && `blue extern` || '';
return ( return (
<Link <Link
key={i} key={link}
href={link} href={link}
className={`${extern} link button`}> className={`${extern} link button`}>
{title} {title}

View File

@ -22,7 +22,7 @@ function RecentNotes() {
{notes?.slice(0, 5) {notes?.slice(0, 5)
.map(({slug, title, mtime}) => { .map(({slug, title, mtime}) => {
return ( return (
<li key={mtime.getTime()} > <li key={slug} >
<Link href={`/notes/${slug}`}>{title}</Link> <Link href={`/notes/${slug}`}>{title}</Link>
</li> </li>
); );

View File

@ -30,7 +30,7 @@ function RecentPosts() {
.map(([slug, post]: any, i: number) => { .map(([slug, post]: any, i: number) => {
return ( return (
<PostBlock <PostBlock
key={i} key={slug}
slug={slug} slug={slug}
title={post.title} title={post.title}
otime={post.otime} /> otime={post.otime} />

View File

@ -12,7 +12,7 @@ function createPathElements(ancestors: Array<{ name: string, path: string }>) {
currentPath += `/${ancestor.path}` currentPath += `/${ancestor.path}`
return ( return (
<> <>
<Link key={id + 1} href={currentPath}>{ancestor.name}</Link> <Link key={currentPath} href={currentPath}>{ancestor.name}</Link>
<> / </> <> / </>
</> </>
); );

View File

@ -12,8 +12,8 @@ function Nav() {
<div className='block'> <div className='block'>
<h2>Navigation</h2> <h2>Navigation</h2>
{ {
nav.map(([slug, info], i) => { nav.map(([slug, info]) => {
return <Link key={i} href={slug} className='button green'>{info.title}</Link> return <Link key={slug} href={slug} className='button green'>{info.title}</Link>
}) })
} }
</div> </div>

View File

@ -43,8 +43,8 @@ function NotesPage() {
|| <table> || <table>
<tbody> <tbody>
{notes.map( {notes.map(
(note: any, i: number) => { (note: any) => {
return (<NoteEntry note={note} key={i} />); return (<NoteEntry note={note} key={note.slug} />);
} }
)} )}
</tbody> </tbody>

View File

@ -26,8 +26,8 @@ function Posts() {
<table> <table>
<tbody> <tbody>
{ {
posts.map(([slug, post]: any, i: number) => { posts.map(([slug, post]: [string, any]) => {
return <tr key={i} style={{ alignItems: 'center' }}> return <tr key={slug} style={{ alignItems: 'center' }}>
<td style={{ display: 'inline-block', textAlign: 'right', fontSize: '0.9rem' }}> <td style={{ display: 'inline-block', textAlign: 'right', fontSize: '0.9rem' }}>
<div style={{ fontStyle: 'italics', fontSize: '.8rem' }}>{ <div style={{ fontStyle: 'italics', fontSize: '.8rem' }}>{
post.mtime && (post.mtime != post.otime) && `Updated ${date.toRelativeDate(new Date(post.mtime))}` post.mtime && (post.mtime != post.otime) && `Updated ${date.toRelativeDate(new Date(post.mtime))}`