Skip to content

Commit c4ec69a

Browse files
committed
Update useToggle
1 parent b9b6980 commit c4ec69a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,13 @@ export function useThrottle(value, interval = 500) {
12301230
}
12311231

12321232
export function useToggle(initialValue) {
1233-
const [on, setOn] = React.useState(initialValue);
1233+
const [on, setOn] = React.useState(() => {
1234+
if (typeof initialValue === "boolean") {
1235+
return initialValue;
1236+
}
1237+
1238+
return Boolean(initialValue);
1239+
});
12341240

12351241
const handleToggle = React.useCallback((value) => {
12361242
if (typeof value === "boolean") {

0 commit comments

Comments
 (0)