From 1d698294a80551daf251c78b4a7ca1803394387a Mon Sep 17 00:00:00 2001 From: John <37978984+johnridesabike@users.noreply.github.com> Date: Tue, 21 Apr 2020 08:24:16 -0400 Subject: [PATCH] Added uncurried hooks. Any hook which can return a function can now return an uncurried function. --- src/React.re | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/src/React.re b/src/React.re index dda79e323..20ba34ff7 100644 --- a/src/React.re +++ b/src/React.re @@ -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: ( @@ -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"; @@ -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";