Skip to content

Commit 6836cfb

Browse files
added hook
1 parent f2b6167 commit 6836cfb

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/index.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { CSSProperties, useState } from 'react';
1+
import React, { CSSProperties, useEffect, useState } from 'react';
22

33
interface ToggleSliderHandleProps extends CSSProperties {
44
size: number | string,
@@ -123,4 +123,15 @@ function ToggleSlider({
123123
);
124124
}
125125

126+
export function useToggleSlider(props?: ToggleSliderProps) {
127+
128+
const [activeState, setActiveState] = useState(props?.active ?? false);
129+
function onToggle(value: boolean) {
130+
setActiveState(value);
131+
}
132+
133+
return [<ToggleSlider onToggle={onToggle} {...props}/>, activeState]
134+
135+
}
136+
126137
export default ToggleSlider;

0 commit comments

Comments
 (0)