@@ -2,7 +2,7 @@ import type { SerializedStyles } from '@emotion/react';
22import { css } from '@emotion/react' ;
33import type { Breakpoint } from '@guardian/source/foundations' ;
44import { from , space , until } from '@guardian/source/foundations' ;
5- import { useEffect , useRef , useState } from 'react' ;
5+ import { useCallback , useEffect , useRef , useState } from 'react' ;
66import { nestedOphanComponents } from '../lib/ophan-helpers' ;
77import { palette } from '../palette' ;
88import { CarouselCount } from './CarouselCount' ;
@@ -358,7 +358,7 @@ export const ScrollableCarousel = ({
358358 * updates the state of cardCount. we use the half of a card because at
359359 * this scroll amount the carousel will snap to that card.
360360 */
361- const updateCardCountOnScroll = ( ) => {
361+ const updateCardCountOnScroll = useCallback ( ( ) => {
362362 const carouselElement = carouselRef . current ;
363363 if ( ! carouselElement ) return ;
364364 const cardWidth = carouselElement . querySelector ( 'li' ) ?. offsetWidth ?? 0 ;
@@ -368,7 +368,7 @@ export const ScrollableCarousel = ({
368368 if ( count !== cardCount ) {
369369 setCardCount ( count ) ;
370370 }
371- } ;
371+ } , [ cardCount ] ) ;
372372
373373 /**
374374 * Throttle scroll events to optimise performance. As we're only using this
@@ -474,7 +474,7 @@ export const ScrollableCarousel = ({
474474 throttleEvent ( updateCardCountOnScroll ) ,
475475 ) ;
476476 } ;
477- } , [ isArticle ] ) ;
477+ } , [ isArticle , updateCardCountOnScroll ] ) ;
478478
479479 return (
480480 < div css = { [ baseContainerStyles , ! isArticle && frontContainerStyles ] } >
0 commit comments