Closed jchavarri closed 2 years ago
Here's an example of the transformation:
let (useState_internal :
Imports.react -> (unit -> 'state) -> 'state * (('state -> 'state) -> unit)
) =
fun (react : Imports.react) (init : unit -> 'state) ->
let result =
Ojs.call
(Imports.react_to_js react)
"useState"
[|Ojs.fun_to_js 1 (fun _ -> Obj.magic (init ()))|]
in
( Obj.magic (Ojs.array_get result 0)
- , fun (updater : 'state -> 'state) ->
- ignore
- (Ojs.apply (Ojs.array_get result 1)
- [| Ojs.fun_to_js 1 (fun (data : Ojs.t) ->
- Obj.magic (updater (Obj.magic data)) ) |] ) )
+ Obj.magic (Ojs.array_get result 1))
let useState initial = useState_internal Imports.react initial
Fixes #100.
The fix consist mostly on inlining the previously generated code by gen_js_api and removing the wrapping over the following functions:
useState
useReducer
Both functions can take only 1 argument, so I don't see any reason why the currying handling is needed in these case.
Added some tests for this as well as a base test for
useState
, which was not existent.