javascript - ReactJS dont take the css styles
问题描述
Technology :
- ReactJS
Todo :
- When user chooses a number I need to change just the background style.
- The style is only maintained if this.state.currentPage === number, otherwise it does not show any style although I require the styles changing the background.
Tried Case :
onClick={this.handleClick} style={this.state.currentPage === number ?
styles.paginationButtons : [styles.paginationButtons,
{backgroundColor:'blue'}]}>
解决方案
Try updating your code so that you supply the dynamic styles to your component without the use of arrays.
You should be able to do so in this way:
style={ (this.state.currentPage === number ? styles.paginationButtons : { backgroundColor:'blue', ...styles.paginationButtons }) }
推荐阅读
- php - 带负号的十进制数字验证
- mysql - SQL查询将两个前面的数字从“2048”更改为“1948”
- javascript - 单击时的表单验证不起作用javascript
- c# - 如何证明弱引用已释放?
- jsf - 我们如何将 jsf 错误消息从 JSF 转换器重定向到由 Backing Bean 支持的文本区域
- apache-spark - 从 Mysql 作为 Stream 读取
- python - Python - Selenium:如何在网页中单击文本为“年份”的元素
- wordpress - 如何在 Jupiter 主题中向我的产品单页添加自定义按钮?
- tfs - 如何在云中进行代码签名?
- 2sxc - 在 2sxc 的代码中使用关系过滤器