diff --git a/src/useSlider.ts b/src/useSlider.ts index 85677b65..6e3a382b 100644 --- a/src/useSlider.ts +++ b/src/useSlider.ts @@ -13,7 +13,7 @@ export interface State { export interface Options { onScrub: (value: number) => void; onScrubStart: () => void; - onScrubStop: () => void; + onScrubStop: (value: number) => void; reverse: boolean; styles: boolean | CSSProperties; vertical?: boolean; @@ -24,12 +24,15 @@ const noop = () => {}; const useSlider = (ref: RefObject, options: Partial = {}): State => { const isMounted = useMountedState(); const isSliding = useRef(false); + const valueRef = useRef(0); const frame = useRef(0); const [state, setState] = useSetState({ isSliding: false, value: 0, }); + valueRef.current = state.value; + useEffect(() => { if (isClient) { const styles = options.styles === undefined ? true : options.styles; @@ -50,7 +53,7 @@ const useSlider = (ref: RefObject, options: Partial = {}): const stopScrubbing = () => { if (isSliding.current && isMounted()) { - (options.onScrubStop || noop)(); + (options.onScrubStop || noop)(valueRef.current); isSliding.current = false; setState({ isSliding: false }); unbindEvents(); diff --git a/stories/useSlider.story.tsx b/stories/useSlider.story.tsx index 9626a8b4..c0700f4b 100644 --- a/stories/useSlider.story.tsx +++ b/stories/useSlider.story.tsx @@ -5,7 +5,11 @@ import ShowDocs from './util/ShowDocs'; const Demo = () => { const ref = React.useRef(null); - const state = useSlider(ref); + const state = useSlider(ref, { + onScrubStop: (value) => { + console.log('onScrubStop', value); + }, + }); return (