【问题标题】:Best practice to be DRY in terms of style in React Native with components such as TextInput?在 React Native 中使用 TextInput 等组件在样式方面保持 DRY 的最佳实践?
【发布时间】:2016-12-29 13:35:27
【问题描述】:

我在多个场景中使用 TextInput 来渲染“表单”元素。它们都具有相同的样式,那么 React Native 在样式方面的良好做法是什么?我的意思是,我可以在每个单独的组件场景中为 TextInput 定义一个样式,但是有没有办法更DRY

【问题讨论】:

    标签: react-native styles components


    【解决方案1】:

    将您的TextInput 包装在您自己的组件中。向它添加样式,并定义您在该组件中经常使用的道具。您还可以传递其他道具(未明确定义),例如使用const { label, value, placeholder, onChange, multiline, onSubmit, ...passProps } = this.props; 然后<TextInput label={label} ... {...passProps} />

    【讨论】:

      猜你喜欢
      • 2019-10-10
      • 1970-01-01
      • 2018-04-03
      • 2018-03-21
      • 2016-07-25
      • 2020-10-11
      • 2011-12-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多