Skip to content

Commit

Permalink
Fix main page React key warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
sashachabin committed Nov 5, 2023
1 parent ed626bb commit 3259e5f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
8 changes: 5 additions & 3 deletions client/components/MainPage/MainPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ import { Marquee } from './Marquee/Marquee';
const cn = classNames.bind(styles);

export function MainPage({ cards, cardsDynamicData, marqueeItems }: MainPageTypes) {
const marqueeItemsData = marqueeItems.map(({ id, attributes: { message } }) => ({ id, message }))

const getDynamicContent = (dynamicId) => {
switch (dynamicId) {
case 'a11y-transport':
return <CardTransportA11y {...cardsDynamicData.a11yTransportCounters} />
case 'traffic-jams':
return <CardTrafficJams score={cardsDynamicData.trafficJams} />
case 'map':
return <CardMap />
return <CardMap />
}
}

Expand All @@ -32,7 +34,7 @@ export function MainPage({ cards, cardsDynamicData, marqueeItems }: MainPageType
<div className={cn(styles.MainPageInner)}>
<div className={cn(styles.MainPageLogo)}>
<Logo />
<h1 className={cn(styles.MainPageTitle)}>Транспорт<br/>Екатеринбурга</h1>
<h1 className={cn(styles.MainPageTitle)}>Транспорт<br />Екатеринбурга</h1>
</div>

<div className={styles.MainPageCardGrid}>
Expand All @@ -54,7 +56,7 @@ export function MainPage({ cards, cardsDynamicData, marqueeItems }: MainPageType
})}
</div>

<Marquee items={marqueeItems.map(({ attributes: { message } }) => message)} />
<Marquee items={marqueeItemsData} />
</div>
</div>
);
Expand Down
6 changes: 4 additions & 2 deletions client/components/MainPage/Marquee/Marquee.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ export function Marquee({ items }: MarqueeProps) {
return (
<div className={cn(styles.Marquee)}>
<div className={cn(styles.MarqueeInner)}>
{items.map((item) => (
<div className={cn(styles.MarqueeItem)}>{item}</div>
{items.map(({ id, message }) => (
<div key={id} className={cn(styles.MarqueeItem)}>
{message}
</div>
))}
</div>
</div>
Expand Down
7 changes: 6 additions & 1 deletion client/components/MainPage/Marquee/Marquee.types.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
export type MarqueeProps = {
items: string[];
items: MarqueeItem[],
};

type MarqueeItem = {
id: number,
message: string,
}

1 comment on commit 3259e5f

@ekbdev
Copy link

@ekbdev ekbdev commented on 3259e5f Nov 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for transport ready!

✅ Preview
https://transport-djwo0qnwm-ekbdev.vercel.app
https://ekbdev-transport-fix-main-page-key-warns.vercel.app

Built with commit 3259e5f.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.