Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix main page React key warnings #86

Merged
merged 1 commit into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
}
Loading