Skip to content

Commit

Permalink
Added uncurried hooks. Any hook which can return a function can now r…
Browse files Browse the repository at this point in the history
…eturn an uncurried function.
  • Loading branch information
johnridesabike committed Apr 21, 2020
1 parent 16da41d commit 1d69829
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions src/React.re
Expand Up @@ -130,12 +130,23 @@ external useState:
([@bs.uncurry] (unit => 'state)) => ('state, ('state => 'state) => unit) =
"useState";

[@bs.module "react"]
external useStateU:
([@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 useReducerU:
([@bs.uncurry] (('state, 'action) => 'state), 'state) =>
('state, (. 'action) => unit) =
"useReducer";

[@bs.module "react"]
external useReducerWithMapState:
(
Expand All @@ -146,6 +157,16 @@ external useReducerWithMapState:
('state, 'action => unit) =
"useReducer";

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

[@bs.module "react"]
external useEffect: ([@bs.uncurry] (unit => option(unit => unit))) => unit =
"useEffect";
Expand Down Expand Up @@ -266,49 +287,92 @@ external useMemo7:

/* This is used as return values */
type callback('input, 'output) = 'input => 'output;
type callbackU('input, 'output) = (. 'input) => 'output;

[@bs.module "react"]
external useCallback:
([@bs.uncurry] ('input => 'output)) => callback('input, 'output) =
"useCallback";
[@bs.module "react"]
external useCallbackU:
([@bs.uncurry] ('input => 'output)) => callbackU('input, 'output) =
"useCallback";
[@bs.module "react"]
external useCallback0:
([@bs.uncurry] ('input => 'output), [@bs.as {json|[]|json}] _) =>
callback('input, 'output) =
"useCallback";
[@bs.module "react"]
external useCallback0U:
([@bs.uncurry] ('input => 'output), [@bs.as {json|[]|json}] _) =>
callbackU('input, 'output) =
"useCallback";
[@bs.module "react"]
external useCallback1:
([@bs.uncurry] ('input => 'output), array('a)) => callback('input, 'output) =
"useCallback";
[@bs.module "react"]
external useCallback1U:
([@bs.uncurry] ('input => 'output), array('a)) => callbackU('input, 'output) =
"useCallback";
[@bs.module "react"]
external useCallback2:
([@bs.uncurry] ('input => 'output), ('a, 'b)) => callback('input, 'output) =
"useCallback";
[@bs.module "react"]
external useCallback2U:
([@bs.uncurry] ('input => 'output), ('a, 'b)) => callbackU('input, 'output) =
"useCallback";
[@bs.module "react"]
external useCallback3:
([@bs.uncurry] ('input => 'output), ('a, 'b, 'c)) =>
callback('input, 'output) =
"useCallback";
[@bs.module "react"]
external useCallback3U:
([@bs.uncurry] ('input => 'output), ('a, 'b, 'c)) =>
callbackU('input, 'output) =
"useCallback";
[@bs.module "react"]
external useCallback4:
([@bs.uncurry] ('input => 'output), ('a, 'b, 'c, 'd)) =>
callback('input, 'output) =
"useCallback";
[@bs.module "react"]
external useCallback4U:
([@bs.uncurry] ('input => 'output), ('a, 'b, 'c, 'd)) =>
callbackU('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 useCallback5U:
([@bs.uncurry] ('input => 'output), ('a, 'b, 'c, 'd, 'e)) =>
callbackU('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 useCallback6U:
([@bs.uncurry] ('input => 'output), ('a, 'b, 'c, 'd, 'e, 'f)) =>
callbackU('input, 'output) =
"useCallback";
[@bs.module "react"]
external useCallback7:
([@bs.uncurry] ('input => 'output), ('a, 'b, 'c, 'd, 'e, 'f, 'g)) =>
callback('input, 'output) =
"useCallback";
[@bs.module "react"]
external useCallback7U:
([@bs.uncurry] ('input => 'output), ('a, 'b, 'c, 'd, 'e, 'f, 'g)) =>
callbackU('input, 'output) =
"useCallback";

[@bs.module "react"] external useContext: Context.t('any) => 'any = "useContext";

Expand Down

0 comments on commit 1d69829

Please sign in to comment.