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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions src/React.re
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,77 @@ 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:
([@bs.uncurry] (('state, 'action) => 'state), 'state) =>
('state, (. 'action) => unit) =
"useReducer";

[@bs.module "react"]
external useReducerWithMapState:
(
[@bs.uncurry] (('state, 'action) => 'state),
'initialState,
[@bs.uncurry] ('initialState => 'state)
) =>
('state, (. 'action) => unit) =
"useReducer";

type callback('input, 'output) = (. 'input) => 'output;

[@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.

"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"]
Expand Down