reactjs - 如何改变 react 组件的颜色

标签 reactjs reactstrap

在reactstrap中,我们可以使用默认样式设置颜色(例如主要、次要、成功、警告......),但是如何使用十六进制颜色代码更改它? 例如,如何将“警告”更改为“#008080”?

<AppSwitch
  className={'mx-1'}
  variant={'pill'}
  color={'warning'} //it dones't work with {'#008080'}
  default checked
  onChange={this.handler} />

我也尝试过类似的方法,但也没有成功:

state = {
  color: '#008080'
}


<AppSwitch
  className={'mx-1'}
  variant={'pill'}
  color={'this.state.color'} 
  default checked
  onChange={this.handler} />

最佳答案

你应该在常量中定义它:

const hexColor = {
  color: '#008080'
};

<AppSwitch
  className={'mx-1'}
  variant={'pill'}
  color={hexColor[color]} //it dones't work with {'#008080'}
  default checked
  onChange={this.handler} />

关于reactjs - 如何改变 react 组件的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56390570/

相关文章:

javascript - 类型错误 : this is undefined; can't access its "props" property

reactjs - CKEditorError : ckeditor-duplicated-modules: Some CKEditor 5 modules are duplicated

javascript - 添加 svg 图像作为语义 UI 输入的图标

javascript - 项目显示何时应隐藏

javascript - React JS如何显示数组内包含数组的JSON

twitter-bootstrap - 在create-react-app中,添加Bootstrap 4?

swift - 如何导入fabric-webpack到react-native?

javascript - 如何在 next.js 应用程序中从服务器端获取客户端的 IP 地址?

reactjs - Reactstrap 和 React-Bootstrap 有什么区别?

css - 使用 reactstrap Spinner 不显示圆形装载机