Skip to content

Commit

Permalink
Merge pull request #981 from lesha1201/fix/embla-api-initialized-with…
Browse files Browse the repository at this point in the history
…-stale-options

[Bug]: `useEmblaCarousel` initializes Embla with stale options in certain cases
  • Loading branch information
davidjerleke authored Aug 26, 2024
2 parents 89a298b + e1c0df5 commit 905bef5
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions packages/embla-carousel-react/src/components/useEmblaCarousel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ function useEmblaCarousel(
if (emblaApi) emblaApi.reInit(storedOptions.current, storedPlugins.current)
}, [emblaApi])

useEffect(() => {
if (areOptionsEqual(storedOptions.current, options)) return
storedOptions.current = options
reInit()
}, [options, reInit])

useEffect(() => {
if (arePluginsEqual(storedPlugins.current, plugins)) return
storedPlugins.current = plugins
reInit()
}, [plugins, reInit])

useEffect(() => {
if (canUseDOM() && viewport) {
EmblaCarousel.globalOptions = useEmblaCarousel.globalOptions
Expand All @@ -47,18 +59,6 @@ function useEmblaCarousel(
}
}, [viewport, setEmblaApi])

useEffect(() => {
if (areOptionsEqual(storedOptions.current, options)) return
storedOptions.current = options
reInit()
}, [options, reInit])

useEffect(() => {
if (arePluginsEqual(storedPlugins.current, plugins)) return
storedPlugins.current = plugins
reInit()
}, [plugins, reInit])

return [<EmblaViewportRefType>setViewport, emblaApi]
}

Expand Down

0 comments on commit 905bef5

Please sign in to comment.