Skip to content

Commit 23ecfdb

Browse files
committed
refactor: use memoized data to avoid re-rendering
1 parent 57f8f62 commit 23ecfdb

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/views/Home/components/SpeakersCarousel/SpeakerSwiper.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const StyledSlideText = styled.p`
3838
const SpeakerSwiper: FC<React.PropsWithChildren<unknown>> = () => {
3939
const { isLoading, data, error } = useFetchSpeakers();
4040

41-
const swiperSpeakers = data?.sort(() => 0.5 - Math.random()).slice(0, 20);
41+
const cachedSpeakers = React.useMemo(()=>data?.sort(() => 0.5 - Math.random()).slice(0, 20), [data]);
4242

4343
if (error) {
4444
Sentry.captureException(error);
@@ -47,7 +47,7 @@ const SpeakerSwiper: FC<React.PropsWithChildren<unknown>> = () => {
4747
return (
4848
<>
4949
{isLoading && <p>Loading</p>}
50-
{conferenceData.carrousel.enabled && swiperSpeakers && (
50+
{conferenceData.carrousel.enabled && cachedSpeakers && (
5151
<Swiper
5252
/*autoplay={{
5353
delay: 5000,
@@ -82,7 +82,7 @@ const SpeakerSwiper: FC<React.PropsWithChildren<unknown>> = () => {
8282
modules={[/*Autoplay,*/ Parallax]}
8383
className="mySwiper"
8484
>
85-
{swiperSpeakers.map((speaker) => (
85+
{cachedSpeakers.map((speaker) => (
8686
<SwiperSlide key={speaker.id}>
8787
<Link
8888
to={`${ROUTE_SPEAKER_DETAIL}/${speaker.id}`}

0 commit comments

Comments
 (0)