Updated & Optimized UpcomingEvents Component#33
Updated & Optimized UpcomingEvents Component#33nayakOPS wants to merge 4 commits intoKathFOSS-Club:mainfrom
Conversation
|
Hi @nayakOPS, Could you explain a bit about how this component will re-render? Also, there’s another library called |
|
@nayakOPS , Any updates ? |
|
Hi @bhimrazy , |
|
Hi @bhimrazy, Thank you for your patience! Why Use React.memo? The component receives no props (it directly uses the upcomingEvents data from the imported file). However, wrapping it in React.memo ensures that if this component is ever used in a parent component that re-renders frequently, the UpcomingEvents component won’t re-render unless its props change. Example of Re-renders: Without React.memo, every time the ParentComponent re-renders (e.g., when the button is clicked), the UpcomingEvents component will also re-render, even though its props (none in this case) haven’t changed. With React.memo, the UpcomingEvents component will skip re-renders unless its props change, improving performance. Regarding react-scan: |
|
Thank you for the explanation, @nayakOPS! I understood the purpose of If the component is later used in a parent component that re-renders frequently, we can consider adding Let’s use |
| import { upcomingEvents as events } from "../data/upcoming-events"; | ||
|
|
||
| export default function UpcomingEvents() { | ||
| const UpcomingEvents = React.memo(() => { |
There was a problem hiding this comment.
| const UpcomingEvents = React.memo(() => { | |
| const UpcomingEvents = () => { |
| </Box> | ||
| ); | ||
| } | ||
| }); |
Feature Update UpcomingEvents Component
This PR improves the
UpcomingEventscomponent by optimizing its performance and enhancing its code readability.Key Changes
Added
React.memo:UpcomingEventscomponent, improving performance.Destructured Properties in
map:title,description,image, andlinkdirectly in theevents.map()function.Why These Changes?
React.memoensures the component re-renders only when its props change, which is essential for large-scale applications.