Material ui 如何在react绑定中跨组件组合道具?
我目前正在编写一个材料UI react binding,我想知道如何重用以前定义的道具 Select组件将所有输入道具分散到其自身的底层react js库中。这是通过传播道具来实现的,但是在ReasonML中,这是不鼓励的,因为打字会丢失 作为一个临时解决方案,我将道具从一个复制到另一个,但这是不可伸缩的。如果有人能提出合理的正确做法,我将不胜感激 谢谢 输入模块定义:Material ui 如何在react绑定中跨组件组合道具?,material-ui,ffi,reason,bucklescript,reason-react,Material Ui,Ffi,Reason,Bucklescript,Reason React,我目前正在编写一个材料UI react binding,我想知道如何重用以前定义的道具 Select组件将所有输入道具分散到其自身的底层react js库中。这是通过传播道具来实现的,但是在ReasonML中,这是不鼓励的,因为打字会丢失 作为一个临时解决方案,我将道具从一个复制到另一个,但这是不可伸缩的。如果有人能提出合理的正确做法,我将不胜感激 谢谢 输入模块定义: module Input = { [@bs.module "material-ui/Input"] external re
module Input = {
[@bs.module "material-ui/Input"] external reactClass : ReasonReact.reactClass = "default";
let make =
(
~disableUnderline: option(bool)=?,
~disabled: option(bool)=?,
~error: option(bool)=?,
~autoFocus: option(bool)=?,
~fullWidth: option(bool)=?,
~style: option(ReactDOMRe.style)=?,
~value: option(string)=?,
~onChange: option((ReactEventRe.Form.t => unit))=?,
~placeholder: option(string)=?,
~className: option(string)=?,
~inputType: option(string)=?,
children
) =>
ReasonReact.wrapJsForReason(
~reactClass,
~props=
Js.Nullable.(
{
"disableUnderline": unwrap_bool(disableUnderline),
"disabled": unwrap_bool(disabled),
"error": unwrap_bool(error),
"fullWidth": unwrap_bool(fullWidth),
"autoFocus": unwrap_bool(autoFocus),
"style": from_opt(style),
"placeholder": from_opt(placeholder),
"className": from_opt(className),
"type": from_opt(inputType),
"value": from_opt(value),
"onChange": from_opt(onChange)
}
),
children
);
};
module Select = {
[@bs.module "material-ui/Select"] external reactClass : ReasonReact.reactClass = "default";
let make =
(
~autoWidth: option(bool)=?,
~classes: option(Js.t({..}))=?,
~className: option(string)=?,
~displayEmpty: option(bool)=?,
~input: option(ReasonReact.reactElement)=?,
~inputClasses: option(Js.t({..}))=?,
~native: option(bool)=?,
~multiple: option(bool)=?,
~menuProps: option(Js.t({..}))=?,
~renderValue: option((unit => unit)),
~value: option('a)=?,
~style: option(ReactDOMRe.style)=?,
/* Input Props*/
~disableUnderline: option(bool)=?,
~disabled: option(bool)=?,
~error: option(bool)=?,
~autoFocus: option(bool)=?,
~fullWidth: option(bool)=?,
~value: option(string)=?,
~onChange: option((ReactEventRe.Form.t => unit))=?,
~placeholder: option(string)=?,
~className: option(string)=?,
~inputType: option(string)=?,
children
) =>
ReasonReact.wrapJsForReason(
~reactClass,
~props=
Js.Nullable.(
{
"autoWidth": unwrap_bool(autoWidth),
"classes": from_opt(classes),
"className": from_opt(className),
"displayEmpty": unwrap_bool(displayEmpty),
"input": from_opt(input),
"InputClasses": from_opt(inputClasses),
"native": unwrap_bool(native),
"multiple": unwrap_bool(multiple),
"MenuProps": from_opt(menuProps),
"renderValue": from_opt(renderValue),
"value": from_opt(value),
"style": from_opt(style),
/* Input Props*/
"disableUnderline": unwrap_bool(disableUnderline),
"disabled": unwrap_bool(disabled),
"error": unwrap_bool(error),
"fullWidth": unwrap_bool(fullWidth),
"autoFocus": unwrap_bool(autoFocus),
"style": from_opt(style),
"placeholder": from_opt(placeholder),
"className": from_opt(className),
"type": from_opt(inputType),
"value": from_opt(value),
"onChange": from_opt(onChange)
}
),
children
);
};
选择模块定义:
module Input = {
[@bs.module "material-ui/Input"] external reactClass : ReasonReact.reactClass = "default";
let make =
(
~disableUnderline: option(bool)=?,
~disabled: option(bool)=?,
~error: option(bool)=?,
~autoFocus: option(bool)=?,
~fullWidth: option(bool)=?,
~style: option(ReactDOMRe.style)=?,
~value: option(string)=?,
~onChange: option((ReactEventRe.Form.t => unit))=?,
~placeholder: option(string)=?,
~className: option(string)=?,
~inputType: option(string)=?,
children
) =>
ReasonReact.wrapJsForReason(
~reactClass,
~props=
Js.Nullable.(
{
"disableUnderline": unwrap_bool(disableUnderline),
"disabled": unwrap_bool(disabled),
"error": unwrap_bool(error),
"fullWidth": unwrap_bool(fullWidth),
"autoFocus": unwrap_bool(autoFocus),
"style": from_opt(style),
"placeholder": from_opt(placeholder),
"className": from_opt(className),
"type": from_opt(inputType),
"value": from_opt(value),
"onChange": from_opt(onChange)
}
),
children
);
};
module Select = {
[@bs.module "material-ui/Select"] external reactClass : ReasonReact.reactClass = "default";
let make =
(
~autoWidth: option(bool)=?,
~classes: option(Js.t({..}))=?,
~className: option(string)=?,
~displayEmpty: option(bool)=?,
~input: option(ReasonReact.reactElement)=?,
~inputClasses: option(Js.t({..}))=?,
~native: option(bool)=?,
~multiple: option(bool)=?,
~menuProps: option(Js.t({..}))=?,
~renderValue: option((unit => unit)),
~value: option('a)=?,
~style: option(ReactDOMRe.style)=?,
/* Input Props*/
~disableUnderline: option(bool)=?,
~disabled: option(bool)=?,
~error: option(bool)=?,
~autoFocus: option(bool)=?,
~fullWidth: option(bool)=?,
~value: option(string)=?,
~onChange: option((ReactEventRe.Form.t => unit))=?,
~placeholder: option(string)=?,
~className: option(string)=?,
~inputType: option(string)=?,
children
) =>
ReasonReact.wrapJsForReason(
~reactClass,
~props=
Js.Nullable.(
{
"autoWidth": unwrap_bool(autoWidth),
"classes": from_opt(classes),
"className": from_opt(className),
"displayEmpty": unwrap_bool(displayEmpty),
"input": from_opt(input),
"InputClasses": from_opt(inputClasses),
"native": unwrap_bool(native),
"multiple": unwrap_bool(multiple),
"MenuProps": from_opt(menuProps),
"renderValue": from_opt(renderValue),
"value": from_opt(value),
"style": from_opt(style),
/* Input Props*/
"disableUnderline": unwrap_bool(disableUnderline),
"disabled": unwrap_bool(disabled),
"error": unwrap_bool(error),
"fullWidth": unwrap_bool(fullWidth),
"autoFocus": unwrap_bool(autoFocus),
"style": from_opt(style),
"placeholder": from_opt(placeholder),
"className": from_opt(className),
"type": from_opt(inputType),
"value": from_opt(value),
"onChange": from_opt(onChange)
}
),
children
);
};
您可以使用currying和
Js.Obj.assign
来实现这一点:
let common=(reactClass,props,~commonProp1,~commonProp2,children)=>
ReasonReact.wrapJsForReason(
~z~课堂上,
~props=Js.Obj.assign(props{
“commonProp1”:commonProp1,
“commonProp2”:commonProp2
}),
儿童
);
模块输入={
[@bs.module“物料界面/输入”]外部反应类:ReasonReact.reactClass=“默认”;
让make=(~inputProp1,~inputProp2)=>common(reactClass{
“inputProp1”:inputProp1,
“inputProp2”:inputProp2
});
};
模块选择={
[@bs.module“物料界面/选择”]外部反应类:ReasonReact.reactClass=“默认”;
让make=(~selectProp1,~selectProp2)=>common(reactClass{
“selectProp1”:selectProp1,
“selectProp2”:selectProp2
});
};
在每个make
函数中,部分应用了common
,并且由于currying将使用自己的参数“扩展”make函数。实际上,例如Input.make
的类型签名将是~inputProp1=>~inputProp2=>~commonProp1=>~commonProp2=>…