Binding to an external React component
module SupervisedUserCircleOutlined = {
@react.component @module("@mui/icons-material/SupervisedUserCircle")
external make: unit => React.element = "default"
}
@react.component
let make = () => {
<SupervisedUserCircleOutlined color={Mui.Colors.red.c400} fontSize="26px" />
}
@as
decorator
@as
is used to map to JavaScript attribute names that cannot be expressed in ReScript (such as keywords).
For example, in JsxDOM.domProps
@as("type")
type_?: string /* has a fixed but large-ish set of possible values */ /* use this one. Previous one is deprecated */,
and in @react.component
module Comp = {
@react.component
let make =
(@as("open") ~_open, @as("type") ~_type) =>
<Modal _open _type>
<Description />
</Modal>
}
References
- https://github.com/cca-io/rescript-mui/blob/34a4a79eefcaa4e87d7804e03ef57b6411bed4e8/documentation/icons.md
- https://github.com/rescript-lang/rescript-compiler/blob/c6347190a70337652863c925191e1ab49a03697c/jscomp/others/jsxDOMU.res#L260-L261
- https://rescript-lang.org/docs/react/latest/migrate-react#mangling-the-prop-name