File tree Expand file tree Collapse file tree
packages/react/src/LazyVideo Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import {
1010 type MutableRefObject ,
1111 useState ,
1212 type ReactNode ,
13+ useMemo ,
1314} from "react" ;
1415import type { LazyVideoProps } from "../types/lazyVideoTypes" ;
1516import { fillStyles , transparentGif } from "../lib/styles" ;
@@ -186,13 +187,15 @@ function ResponsiveSource({
186187 // Make an object suitable for useMediaQueries that uses indexes from the
187188 // mediaSrcs obj as it's keys so there won't be any issues with multiple
188189 // media queries using the same asset.
189- const indexedQueries = Object . keys ( mediaSrcs ) . reduce < Record < number , string > > (
190- ( queries , mediaQuery , index ) => {
191- queries [ index ] = mediaQuery ;
192- return queries ;
193- } ,
194- { } ,
195- ) ;
190+ const indexedQueries = useMemo ( ( ) => {
191+ return Object . keys ( mediaSrcs ) . reduce < Record < number , string > > (
192+ ( queries , mediaQuery , index ) => {
193+ queries [ index ] = mediaQuery ;
194+ return queries ;
195+ } ,
196+ { } ,
197+ ) ;
198+ } , [ mediaSrcs ] ) ;
196199
197200 // Find the src url that is currently active
198201 const { matches } = useMediaQueries < typeof indexedQueries > ( indexedQueries ) ;
You can’t perform that action at this time.
0 commit comments