Skip to content

Commit df0abdc

Browse files
committed
fix(changelog): use stable keys for list items
Replaces index-based keys in the Changelog component with more stable and unique keys derived from the item data. Using array indices as keys is an anti-pattern in React that can lead to incorrect rendering and performance issues when the list is modified. This change ensures that each list element has a consistent and unique identifier, resolving potential bugs and console warnings. The `readonly` keyword was also added to the component's props for better type safety.
1 parent 670175a commit df0abdc

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/components/Changelog.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { MobileChangelog } from "./MobileChangelog";
77
import { changelogItems } from "../data/changelog";
88

99
interface ChangelogProps {
10-
isModal?: boolean;
11-
onClose?: () => void;
10+
readonly isModal?: boolean;
11+
readonly onClose?: () => void;
1212
}
1313

1414
export function Changelog({ isModal = false, onClose }: ChangelogProps) {
@@ -61,7 +61,7 @@ export function Changelog({ isModal = false, onClose }: ChangelogProps) {
6161
{/* Timeline */}
6262
<div className="relative space-y-8">
6363
{changelogItems.map((item, index) => (
64-
<div key={index} className="relative flex items-start sm:space-x-4">
64+
<div key={`${item.version}-${item.date}`} className="relative flex items-start sm:space-x-4">
6565
{/* Date and Version */}
6666
<div className="w-24 shrink-0 pr-4 text-right sm:w-32 sm:pr-0 sm:text-left">
6767
<p className="text-sm font-medium text-gray-700 dark:text-gray-300">
@@ -83,9 +83,9 @@ export function Changelog({ isModal = false, onClose }: ChangelogProps) {
8383
New
8484
</h3>
8585
<ul className="list-disc space-y-1 pl-5 text-gray-700 dark:text-gray-300">
86-
{item.changes.new.map((change, i) => (
86+
{item.changes.new.map((change) => (
8787
<li
88-
key={i}
88+
key={`new-${change.slice(0, 50)}`}
8989
dangerouslySetInnerHTML={parseMarkdown(change)}
9090
/>
9191
))}
@@ -99,9 +99,9 @@ export function Changelog({ isModal = false, onClose }: ChangelogProps) {
9999
Improved
100100
</h3>
101101
<ul className="list-disc space-y-1 pl-5 text-gray-700 dark:text-gray-300">
102-
{item.changes.improved.map((change, i) => (
102+
{item.changes.improved.map((change) => (
103103
<li
104-
key={i}
104+
key={`improved-${change.slice(0, 50)}`}
105105
dangerouslySetInnerHTML={parseMarkdown(change)}
106106
/>
107107
))}
@@ -115,9 +115,9 @@ export function Changelog({ isModal = false, onClose }: ChangelogProps) {
115115
Fixed
116116
</h3>
117117
<ul className="list-disc space-y-1 pl-5 text-gray-700 dark:text-gray-300">
118-
{item.changes.fixed.map((change, i) => (
118+
{item.changes.fixed.map((change) => (
119119
<li
120-
key={i}
120+
key={`fixed-${change.slice(0, 50)}`}
121121
dangerouslySetInnerHTML={parseMarkdown(change)}
122122
/>
123123
))}

0 commit comments

Comments
 (0)