Skip to content
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

Merged
merged 3 commits into from
Aug 29, 2021

Conversation

BUPTlhuanyu
Copy link
Contributor

No description provided.

@Justineo
Copy link
Member

Justineo commented Aug 8, 2021

Why not just add a force parameter to the useToggle hook’s toggle callback?

@otakustay
Copy link
Member

We can add force parameter to both useBoolean and useToggle

@BUPTlhuanyu
Copy link
Contributor Author

maybe the useToggle and useSwitch can be replaced by useToggle + force parameter.

@otakustay
Copy link
Member

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);

@BUPTlhuanyu
Copy link
Contributor Author

BUPTlhuanyu commented Aug 8, 2021

@otakustay all right, i gonna fix it. #98

@@ -7,8 +7,8 @@ const reducers = {
off() {
return false;
},
toggle(value: boolean) {
return !value;
toggle(prevState: boolean, arg: any) {
Copy link
Member

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

Copy link
Contributor Author

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>

Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

@otakustay otakustay merged commit 7b786e1 into ecomfe:master Aug 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants