[英]Override inner element properties in React components
I have a React
component that consists of other components and uses semantic-ui-react
. 我有一个由其他组件组成的React
组件,并使用semantic-ui-react
。 It looks like: 看起来像:
export const RadioGroup = (props) => {
const { value, options, label, onChange, margin, widths, ...baseProps } = props
return (
<InlineFormGroup margin={margin} widths={widths}>
{/* eslint-disable-next-line jsx-a11y/label-has-for */}
{label && <label>{label}</label>}
{options.map(option =>
<BaseSemanticInput
...
And a plenty of stuff inside that I show by ...
. 和很多里面的东西,我的表现...
。 What I want is to have another component RadioGroupVertical
that would be almost identical to the RadioGroup
shown above except it should have group
property on InlineFormGroup
. 我想要的是拥有另一个组件RadioGroupVertical
,该组件与上面显示的RadioGroup
几乎相同,除了它应该在InlineFormGroup
上具有group
属性。 I kind of do not want to copy-paste large component to do such a small edit but not sure how to do such property modification. 我有点不想复制粘贴大型组件来进行如此小的编辑,但是不确定如何进行这种属性修改。
not sure if I understood exactly but: 不知道我是否完全理解,但是:
let otherProps = {};
if(baseProps && baseProps.group) {
otherProps.group = baseProps.group;
}
<InlineFormGroup margin={margin} widths={widths} {...otherProps}>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.