-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add useToggleOrSet for convenience #99
Conversation
Why not just add a |
We can add force parameter to both useBoolean and useToggle |
maybe the useToggle and useSwitch can be replaced by useToggle + |
I prefer this: const [value, {toggle}] = useBoolean();
toggle(true /false);
const [value, on, off, toggle] = uswSwitch();
toggle(true / false);
const [value, toggle] = useToggle();
toggle(true / false); |
@otakustay all right, i gonna fix it. #98 |
packages/boolean/src/index.ts
Outdated
@@ -7,8 +7,8 @@ const reducers = { | |||
off() { | |||
return false; | |||
}, | |||
toggle(value: boolean) { | |||
return !value; | |||
toggle(prevState: boolean, arg: any) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
arg
should be boolean, strong typed hooks are always better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type will be incorrect when i use the function as a event handler or some other callback,e.g.
<div on-click = { useToglle }></on-click>
<custom-comp on-selected= { useToggle }></custom-comp>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decide to accept this kind of "hacking", but please change its type to unknown
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
No description provided.