-
Notifications
You must be signed in to change notification settings - Fork 350
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
Add uncurried hooks #551
Changes from 1 commit
49dab95
6c2f27f
6fde558
0d19f0d
e6bba61
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -419,6 +419,76 @@ external useImperativeHandle7: | |
unit = | ||
"useImperativeHandle"; | ||
|
||
module Uncurried = { | ||
[@bs.module "react"] | ||
external useState: | ||
([@bs.uncurry] (unit => 'state)) => | ||
('state, (. ('state => 'state)) => unit) = | ||
"useState"; | ||
|
||
[@bs.module "react"] | ||
external useReducer: | ||
((. 'state, 'action) => 'state, 'state) => ('state, (. 'action) => unit) = | ||
"useReducer"; | ||
|
||
[@bs.module "react"] | ||
external useReducerWithMapState: | ||
( | ||
[@bs.uncurry] (('state, 'action) => 'state), | ||
'initialState, | ||
'initialState => 'state | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think we should go ahead and add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. As a separate PR that would be great. |
||
) => | ||
('state, (. 'action) => unit) = | ||
"useReducer"; | ||
|
||
type callback('input, 'output) = (. 'input) => 'output; | ||
|
||
[@bs.module "react"] | ||
external useCallback: | ||
([@bs.uncurry] ('input => 'output)) => callback('input, 'output) = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pretty sure you want to do all of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of the However I did just discover another bug. It doesn’t look like Reason is good at handling arity-zero uncurried functions. I’m not sure what the best way around that is, unless I’m missing something. Seems to be related to reasonml/reason#2357 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
"useCallback"; | ||
[@bs.module "react"] | ||
external useCallback0: | ||
([@bs.uncurry] ('input => 'output), [@bs.as {json|[]|json}] _) => | ||
callback('input, 'output) = | ||
"useCallback"; | ||
[@bs.module "react"] | ||
external useCallback1: | ||
([@bs.uncurry] ('input => 'output), array('a)) => | ||
callback('input, 'output) = | ||
"useCallback"; | ||
[@bs.module "react"] | ||
external useCallback2: | ||
([@bs.uncurry] ('input => 'output), ('a, 'b)) => | ||
callback('input, 'output) = | ||
"useCallback"; | ||
[@bs.module "react"] | ||
external useCallback3: | ||
([@bs.uncurry] ('input => 'output), ('a, 'b, 'c)) => | ||
callback('input, 'output) = | ||
"useCallback"; | ||
[@bs.module "react"] | ||
external useCallback4: | ||
([@bs.uncurry] ('input => 'output), ('a, 'b, 'c, 'd)) => | ||
callback('input, 'output) = | ||
"useCallback"; | ||
[@bs.module "react"] | ||
external useCallback5: | ||
([@bs.uncurry] ('input => 'output), ('a, 'b, 'c, 'd, 'e)) => | ||
callback('input, 'output) = | ||
"useCallback"; | ||
[@bs.module "react"] | ||
external useCallback6: | ||
([@bs.uncurry] ('input => 'output), ('a, 'b, 'c, 'd, 'e, 'f)) => | ||
callback('input, 'output) = | ||
"useCallback"; | ||
[@bs.module "react"] | ||
external useCallback7: | ||
([@bs.uncurry] ('input => 'output), ('a, 'b, 'c, 'd, 'e, 'f, 'g)) => | ||
callback('input, 'output) = | ||
"useCallback"; | ||
}; | ||
|
||
type transitionConfig = {timeoutMs: int}; | ||
|
||
[@bs.module "react"] | ||
|
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.
Swap this input back.