The type of Js.Promise.then_
is
('a => t('b), t('a)) => t('b)
which means the function passed to it must return a, and that then_
itself will return that promise.
You're making two mistakes in your code:
- You are not returning a promise from the function you pass to
then_
- You are not handling the promise returned by
then_
.
The following fixes both:
React.useEffect(_ => {
let _: Js.Promise.t(unit) =
Js.Prmoise.(
ReactNativeAsyncStorage.getItem("jwt")
|> then_(jwt => resolve(Js.log(jwt)))
);
None;
});
let _: Js.Promise.t(unit) = ...
uses the wildcard pattern to discard the result of the following expression. The type of the result is Js.Result.t(unit)
, which is annotated to protect against accidental partial application.
resolve(Js.log(jwt))
will return a promise with the result of calling Js.log
, which is unit
, hence why the resulting promise has the type Js.Promise.t(unit)
.
See the Reason documentation for more on how to use promises.