meafmira / bs-axios

Bucklescript bindings for axios
71 stars 23 forks source link

The example (http GET) doesn't compile in ReasonML #17

Closed aaron-michaux closed 6 years ago

aaron-michaux commented 6 years ago

`
25 │ didMount: (self) => 26 │ 27 │ Js.Promise.( 28 │ Axios.get("/user?ID=12345") 29 │ |> then((response) => resolve(Js.log(response##data))) 30 │ |> catch((error) => resolve(Js.log(error))) 31 │ ), 32 │
33 │ / Js.Promise.( /

This has type: Js.Promise.t(unit) (defined as Js.Promise.t(unit)) But somewhere wanted: unit `

My bsconfig.json contains axios:

"bs-dependencies": [ "reason-react", "bs-jest", "bs-axios", "bs-css" ]

meafmira commented 6 years ago

@aaron-michaux the example is working, but you're using it in didMount method which should return unit not Js.Promise.t(unit). So you should do something like this:

didMount: (_self) => {
    Js.Promise.(
      Axios.get("/user?ID=12345")
      |> then_((response) => resolve(Js.log(response##data)))
      |> catch((error) => resolve(Js.log(error)))
    );
    ();
}