I'm trying to render a component with reason-react after I get data from fetch but I receive a type error. This is my code:
GetData.re:
let get = () => Js.Promise.(
Fetch.fetch("localhost:8000/data.json")
|> then_(Fetch.Response.json)
|> resolve
);
Main.re:
let data = () =>
GetData.get()
|> Js.Promise.then_(result =>
Js.Promise.resolve(
ReactDOMRe.renderToElementWithId(
<ItemsList itemsList=result />,
"root"
)
)
)
And I recive this error:
29 │ let data = () =>
30 │ GetData.get()
31 │ |> Js.Promise.then_(result =>
32 │ Js.Promise.resolve(
. │ ...
37 │ )
38 │ );
This has type:
(Js.Promise.t(list(Item.item))) => Js.Promise.t(unit)
But somewhere wanted:
(Js.Promise.t(Js.Promise.t(Js.Json.t))) => 'a
The incompatible parts:
Js.Promise.t(list(Item.item)) (defined as Js.Promise.t(list(Item.item)))
vs
Js.Promise.t(Js.Promise.t(Js.Json.t)) (defined as
Js.Promise.t(Js.Promise.t(Js.Json.t)))
Further expanded:
list(Item.item)
vs
Js.Promise.t(Js.Json.t) (defined as Js.Promise.t(Js.Json.t))
ninja: build stopped: subcommand failed.
I also try to replace render with simple Js.log(result)
and it works, I try to check type of Js.log
and render
(passing their invocation to a function which takes an int
and watching the error) and they are both unit
Where is my mistake? and is there something like toplevel/utop for Reason? It actually helps a lot in OCaml