Skip to content

Commit cdac6cb

Browse files
Copilotna-trium-144
andcommitted
Use section id instead of array index for element id and sidebar link href
Co-authored-by: na-trium-144 <100704180+na-trium-144@users.noreply.github.com>
1 parent 4dc38c3 commit cdac6cb

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

app/[docs_id]/pageContent.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ export function PageContent(props: PageContentProps) {
8787
}}
8888
>
8989
{dynamicMdContent.map((section, index) => (
90-
<Fragment key={index}>
90+
<Fragment key={section.id}>
9191
<div
9292
className="min-w-1/2 max-w-200 text-justify"
93-
id={`${index}`} // 目次からaタグで飛ぶために必要
93+
id={section.id} // 目次からaタグで飛ぶために必要
9494
ref={(el) => {
9595
sectionRefs.current[index] = el;
9696
}}

app/sidebar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,11 @@ export function Sidebar({ pagesList }: { pagesList: LanguageEntry[] }) {
195195
idx + 1 === currentSectionIndex;
196196
return (
197197
<li
198-
key={idx}
198+
key={section.id}
199199
style={{ marginLeft: section.level - 2 + "em" }}
200200
>
201201
<Link
202-
href={`#${idx + 1}`}
202+
href={`#${section.id}`}
203203
className={
204204
isCurrentSection ? "font-bold" : ""
205205
}

0 commit comments

Comments
 (0)