reason-async-hook icon indicating copy to clipboard operation
reason-async-hook copied to clipboard

feat: add demo

Open ubmit opened this issue 5 years ago • 8 comments

This PR will add a demo

ubmit avatar Jul 19 '20 10:07 ubmit

Which fetch function should be used here

fetch("/user", ~params={
  name,
  age,
})

I was trying to use bs-fetch, but the API seems different and it doesn't return the expected type either. Should I use something else? Also, I can fetch from basically any API, right? For demo purposes, a placeholder API like this https://jsonplaceholder.typicode.com/users should be fine I guess.

ubmit avatar Jul 19 '20 11:07 ubmit

Another thing I've noticed is that there are form values somewhere on the README snippet. Should I use https://github.com/Astrocoders/reform and get the values from there?

ubmit avatar Jul 19 '20 11:07 ubmit

I think it could be just a useState to keep the demo simpler! About the endpoint it could be a simple fastify server that we can spin up together with Webpack like in here https://github.com/fakenickels/es2077-course-slides/blob/master/forms-com-reason/server.js, everything needed for it's on this file and the only dependencies are fastify and fastify-cors

fakenickels avatar Jul 19 '20 12:07 fakenickels

@guilhermedeandrade if u are using bs-fetch, you can use reason-promise to parse the result from Js.Promise.t to Promise.t, something like that:

let requestData = url => Fetch.fetch(url)|>Promise.Js.fromBsPromise|>Promise.Js.toResult;

[@react.component]
let make = () => {
  let (AsyncHook.{ state }, _) = AsyncHook.use((~cb)=> cb(() => requestData(url)));
  <div>
    <form>
    </form>
  </div>
};

vmarcosp avatar Jul 19 '20 14:07 vmarcosp

@guilhermedeandrade if u are using bs-fetch, you can use reason-promise to parse the result from Js.Promise.t to Promise.t, something like that:

let requestData = url => Fetch.fetch(url)|>Promise.Js.fromBsPromise|>Promise.Js.toResult;

[@react.component]
let make = () => {
  let (AsyncHook.{ state }, _) = AsyncHook.use((~cb)=> cb(() => requestData(url)));
  <div>
    <form>
    </form>
  </div>
};

Thank you @vmarcosp! I'll keep this in mind once I start working on it again

ubmit avatar Jul 20 '20 08:07 ubmit

@fakenickels @vmarcosp guys, I'd like to say that I'm sorry but I won't be able to keep working on this (at least not in the near future). I need to focus on some personal things right now. Since I'm still learning Reason, this PR is really challenging and, thus, time-consuming for me.

ubmit avatar Jul 26 '20 19:07 ubmit

No problem! 👊

vmarcosp avatar Jul 26 '20 20:07 vmarcosp

Hey no worries at all! I'm going to reopen your PR so we can continue and merge!

fakenickels avatar Jul 26 '20 22:07 fakenickels