0

Code:

let component = ReasonReact.statelessComponent("Page");
type matchParams = {.
  id: int
};
type match = {.
  params: matchParams
};
type userProps = {.
  match: match
};
let home = <Home />;
let user = (~props:userProps) => <User id=props.match.params.id />;
let make = (_children) => {
  ...component,
  render: (_self) =>
    <div> <Route key="home" exact=false path="/home" component=home />
    <Route key="user" exact=false path="/user/:id" component=user /> </div>
};

Output:

Unbound record field match

on row

let user = (~props:userProps) => <User id=props.match.params.id />;

how to define type, what i do wrong?

glennsl
  • 28,186
  • 12
  • 57
  • 75
kirsanv43
  • 358
  • 2
  • 13

1 Answers1

1

The error is caused by match being a reserved keyword. You should have gotten a better error message though, and I'd consider this a bug in Reason. To solve it, if you need it to compile to match on the JS side, you can use _match instead, otherwise just use a different name.

You also (probably) have a few other problems:

  1. let home = <Home /> is not a function like user. It will probably need to be let home = () => <Home/>

  2. You're defining a record type as the props that will be given to you by the component function. But you'll probably be given a JS object instead of a record. See the Reason guide which explains the difference.

glennsl
  • 28,186
  • 12
  • 57
  • 75
  • but match is property in react-router, how can I use that if I can't use the match word – kirsanv43 Dec 06 '17 at 22:24
  • As I said above, use `_match`. BuckleScript will remove the leading underscore from the generated code. See https://bucklescript.github.io/bucklescript/Manual.html#_object_label_translation_convention – glennsl Dec 06 '17 at 22:35