Rename labelled arguments when creating reason react component

interop
reasonreact

#1

module TextInput = {
type envType;
type onChangeType = (envType, string) => unit;
[@bs.module “text-input”] [@react.component]
external make:
(
~onChange: onChangeType,
~value: string,
~unit_: string=?,
~type_: string=?,
) =>
React.element =
“default”;
};

how to rename labelled arguments type_ -> type, unit_ -> unit.

Thanks for you help guys.

Regards
Srikanth


#2

You can prefix the word with underscore character, it will get stripped away in the compiled JavaScript output. So f(~_unit, ...


#3

Hi yawaramin,

Thanks for the quick reply. it works for the _type -> type, but not for _unit -> unit

here are the changes
Reason part
external make:
(
~onChange: onChangeType,
~value: string,
~_unit: string=?,
~_type: string=?
) =>

bs.js part

React.createElement(TextInput.default, {
onChange: onBonusAmountChange,
value: “”,
_unit: ““€””,
type: “number”
});


#4

Seems there is no need for _unit as labelled parameter at all.
The following works.
[@bs.module “text-input”] [@react.component]
external make:
(
~onChange: onChangeType,
~value: string,
~unit: string=?,
~_type: string=?
) =>
React.element =
“default”;

Thanks


#5

Ah that’s right. unit is not a reserved keyword.


#6

Hi! I ran into the same problem for a react component that wants “aria-label” as a prop: https://reacttraining.com/reach-ui/dialog/
I wasn’t sure how to rename ariaLabel to aria-label.


#7

Binding to aria components is tricky. You can see a guide here on how to make it work: https://dev.to/johnridesabike/binding-external-components-with-aria-properties-in-reasonreact-5pj