我有,
<RadioContainer
nonRepeating="val"
repeating1={this.props.radioGroupAttributes.getIn([variable, 'visibility'])}
repeating2={this.props.radioGroupAttributes.getIn([variable, 'type'])}
repeating3={this.props.allVisible}
repeating4="address"
nonRepeating="xyz"
/>
只有重复属性 1,2 中的参数 variable
在我在代码中多次使用的所有 RadioContainer
组件中有所不同。
我想要,
<RadioContainer
nonRepeating="val"
foo(variable) //should return desired format
nonRepeating="xyz"
/>
foo(variable)
应该扩展或扩展以使上面的代码块看起来像上面的代码块。
RadioContainer
组件被使用了多次,我不想每次编写 RadioContainer
组件时都重复重复的属性。相反,调用一个传递变量的函数,它应该返回所需的格式。
我该如何实现这个目标?
最佳答案
{...foo(variable)} 应该可以解决问题。
<RadioContainer
nonRepeating="val"
nonRepeating="xyz"
{...foo(variable)}
/>
foo(变量)应该返回
{
repeating1 :this.props.radioGroupAttributes.getIn([variable, 'visibility']),
repeating2: this.props.radioGroupAttributes.getIn([variable, 'type']),
repeating3: this.props.allVisible
}
关于javascript - React 传播属性列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51863812/