javascript - React 传播属性列表

标签 javascript reactjs

我有,

<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/

相关文章:

javascript - LessCss 导入失败,带有 url 和 anchor

javascript - React JS - 从外部属性文件读取环境配置

javascript - 从 QML 中的 ListModel 访问 Javascript 数组元素

javascript - 如何测试 Mocha 中的替换方法?

reactjs - 如何将 React 函数中的参数从一个文件传递到另一个文件

javascript - 如何正确使用 @mdx-js/loader 和 create-react-app?

javascript - advancedSlider 图像 slider 插件集成问题与缩略图。

javascript - 可以在 React Native 中检测到 View 组件的触摸吗?

javascript - 如何修复 React 中的 '_this4.props.handleExport' 错误

javascript - 如果我更新一个 React 模块,使得现有代码可以运行,但 Jest 快照测试可能会中断,这应该是一个主要版本冲突吗?