Skip to content

Commit 869f767

Browse files
committed
feat: 🎸 accept any value type in useToggle and cast it to bool
BREAKING CHANGE: now useToggle and useBoolean accept any value type and cast it to boolean.
1 parent 8a9d05e commit 869f767

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/useToggle.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ const useToggle: UseToggle = state => {
99
const [value, setValue] = useState<boolean>(state);
1010

1111
const toggle = (nextValue?: boolean) => {
12-
if (typeof nextValue === 'boolean') {
13-
setValue(nextValue);
12+
if (typeof nextValue !== 'undefined') {
13+
setValue(!!nextValue);
1414
return;
1515
}
1616

0 commit comments

Comments
 (0)