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

Add uncurried hooks #551

Merged
merged 5 commits into from
May 26, 2020
Merged

Add uncurried hooks #551

merged 5 commits into from
May 26, 2020

Conversation

johnridesabike
Copy link
Contributor

let (count, setCount) = React.Uncurried.useState(() => 0);
setCount(. a => a + 1);

The original pull request for this got messed up, so this is re-opening it.

Original PR: #529

Fixes: #530

@rickyvetter
Copy link
Contributor

I think I was getting a little aggressive here. Since they are externals bs.uncurry should be enough. Please swap reducer back to [@bs.uncurry] and then rebuild to resolve conflicts and we can get this in!

src/React.re Outdated

[@bs.module "react"]
external useReducer:
((. 'state, 'action) => 'state, 'state) => ('state, (. 'action) => unit) =
Copy link
Contributor

Choose a reason for hiding this comment

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

Swap this input back.

src/React.re Outdated
(
[@bs.uncurry] (('state, 'action) => 'state),
'initialState,
'initialState => 'state
Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated to your PR but I think this is unsafe. Should probably add bs.uncurry here as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you think we should go ahead and add [@bs.uncurry] to that argument on the regular useReducerWithMapState too?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. As a separate PR that would be great.


[@bs.module "react"]
external useCallback:
([@bs.uncurry] ('input => 'output)) => callback('input, 'output) =
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I was oblivious. Good call for keeping continuity with the other set.

Yah that issue provides a workaround but it is kind of annoying that this error exists. I don't think it should block this PR though - if the feature is never used then a better experience won't be prioritized.

@yawaramin
Copy link
Contributor

@johnridesabike if #574 gets merged, your diff will shrink to only two bindings per hook :-)

@peterpme
Copy link
Collaborator

@johnridesabike @rickyvetter all good here? Would love to get this in a state of mergeability 😄

@johnridesabike
Copy link
Contributor Author

@peterpme I don't have anything else I'm waiting for. Merging is fine with me as long as no one else has any issues.

@rickyvetter rickyvetter merged commit 9917754 into reasonml:master May 26, 2020
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.

Avoid curry for dispatch returned by useReducer
4 participants