Skip to content

Commit

Permalink
fix synchronization for React 18
Browse files Browse the repository at this point in the history
  • Loading branch information
rcbyr committed Sep 18, 2022
1 parent de5b14c commit b89c8c4
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/react.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MutableRefObject, useCallback, useEffect, useRef } from 'react'

import { checkOptions } from './core/utils'
import { equal } from './core/utils'
import KeenSlider, {
KeenSliderHooks,
KeenSliderInstance,
Expand Down Expand Up @@ -38,14 +38,11 @@ export function useKeenSlider<
sliderRef.current = null
}
}, [])

useEffect(() => {
if (!optionsCheckedFirst.current) {
optionsCheckedFirst.current = true
return
}
if (equal(currentOptions.current, options)) return
currentOptions.current = options
if (sliderRef.current) sliderRef.current.update(currentOptions.current)
}, [checkOptions(currentOptions, options)])
}, [options])

return [onRefChange, sliderRef]
}

0 comments on commit b89c8c4

Please sign in to comment.