Skip to content
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

Untyped prop object as escape hatch #50

Open
Ebuall opened this issue Feb 24, 2018 · 1 comment
Open

Untyped prop object as escape hatch #50

Ebuall opened this issue Feb 24, 2018 · 1 comment

Comments

@Ebuall
Copy link

Ebuall commented Feb 24, 2018

Original material-ui library is really flexible in what props it can apply and doesn't go well with such strictly typed language. Even more, they change their api so quickly right now. To play around that, we can have each component to have special prop, that will be included in props directly.
Any inherited, spreadable props can go here, and rarely used props, such as onClick on Typography or tabIndex.
That way we can type better main interface of the component and not worry about some things, that stringly typed anyway.

Here is an example

/* Definition */
module Button = {
  [@bs.module "material-ui/Button"]
  external reactClass : ReasonReact.reactClass = "default";
  let make =
      (
        /* good strictly typed main interface */
        ~onClick: option((ReactEventRe.Mouse.t => unit))=?,
        /* put here whatever you want to apply directly */
        ~unsafeProps=Js.Obj.empty(),
        children
      ) =>
    ReasonReact.wrapJsForReason(
      ~reactClass,
      ~props=Js.Obj.assign(unsafeProps, {
        "onClick": from_opt(onClick)
      }),
      children
    );
};

/* Usage */
let x =
  <Button
    onClick=Js.log2("Hello world")
    unsafeProps={"autofocus": Js.true_} />
@Ebuall
Copy link
Author

Ebuall commented Feb 24, 2018

Few weeks ago I did't find this repo and didn't know about redex, so I started to make my own. My version is much more type-driven, but still pretty small, so I'd rather contribute here. I will make some pulls if you like what I'm proposing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant