-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Data loading and writing bindings #1
Comments
We have a module Remix = {
@module("remix") external useLoaderData: unit => 'a = "useLoaderData"
module type Loadable = {
type t
// TODO: loaderParams definition
type loaderParams = {..}
let loader: loaderParams => Promise.t<t>
}
module Loader = (Loadable: Loadable) => {
include Loadable
let use = (): Loadable.t => useLoaderData()
}
} And then in a route eg. module UsersLoader = Remix.Loader({
type t = array<User.t>
let loader = _ => Api.getUsers()
})
let loader = UsersLoader.loader
@react.component
let default = () => {
let users = UsersLoader.use() // => array<User.t>
} |
I have a WIP PR for how this could look in #19 but I'm not sure about it... Mainly because it doesn't guarantee type safety, you can call the wrong It also comes with some clunkiness in terms of autocomplete and IDE hints. I think also there's no way for the module Data = {
type t = {hi: int}
let loader = _ => Js.Promise.resolve({hi: 5})
}
module Loader = Remix.Loader(Data)
let x = Loader.use()
let y = x.Data.hi
Or type data = {hi: int}
module Loader = Remix.Loader({
type t = data
let loader = _ => Js.Promise.resolve({hi: 5})
})
let x = Loader.use()
let y = x.hi |
The text was updated successfully, but these errors were encountered: