-
-
Notifications
You must be signed in to change notification settings - Fork 734
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: rendering issue with few components using next-i18n on community pages #3384
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React, { useState } from 'react'; | ||
|
||
import EventFilter from '@/components/navigation/EventFilter'; | ||
import EventPostItem from '@/components/navigation/EventPostItem'; | ||
import Heading from '@/components/typography/Heading'; | ||
import Paragraph from '@/components/typography/Paragraph'; | ||
import meetings from '@/config/meetings.json'; | ||
import type { Event } from '@/types/pages/community/Community'; | ||
import { HeadingLevel, HeadingTypeStyle } from '@/types/typography/Heading'; | ||
import { ParagraphTypeStyle } from '@/types/typography/Paragraph'; | ||
import { getEvents } from '@/utils/staticHelpers'; | ||
|
||
const CommunityEvents = () => { | ||
const [events, setEvents] = useState(getEvents(meetings)); | ||
|
||
return ( | ||
<div className='mt-20'> | ||
<div className='items-center justify-between sm:flex'> | ||
<Heading level={HeadingLevel.h2} typeStyle={HeadingTypeStyle.md}> | ||
All Events | ||
</Heading> | ||
<div className='mt-5 sm:mt-0'> | ||
<EventFilter data={meetings} setData={setEvents} /> | ||
</div> | ||
</div> | ||
<div className='mt-10'> | ||
{!events || events.length === 0 ? ( | ||
<div className='flex content-center justify-center'> | ||
<Paragraph typeStyle={ParagraphTypeStyle.md} className='mx-auto mt-5 max-w-2xl'> | ||
No Events. Check back later! | ||
</Paragraph> | ||
</div> | ||
) : ( | ||
<ul className='grid grid-cols-1 gap-5 md:grid-cols-2 lg:grid-cols-3'> | ||
{events.map((event: Event, index: number) => { | ||
return <EventPostItem key={index} id={event.title} post={event} />; | ||
})} | ||
Comment on lines
+35
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid using array indices as React keys. Using array indices as keys can lead to issues with component state and performance when the list items can change (reordering, filtering, etc.). Consider using a unique identifier from the event data. -{events.map((event: Event, index: number) => {
- return <EventPostItem key={index} id={event.title} post={event} />;
+{events.map((event: Event) => {
+ return <EventPostItem key={event.title} id={event.title} post={event} />;
|
||
</ul> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CommunityEvents; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Optimize state initialization to prevent unnecessary calculations.
The
getEvents(meetings)
call in useState will run on every render. Consider optimizing this by either:Or with useMemo: