admin管理员组文章数量:1387383
I'm using react.js and manage most of the style attributes via react, too. If I have a, for example, a success and an error button I want to apply a different background color to them.
Right now, I'm doing this with jQuery's extend function:
<span style={$.extend({background: 'forestgreen'},this.state.buttonStyle)}></span>
But I'm wondering if there is a better and maybe more readable solution for this. Any advice?
I'm using react.js and manage most of the style attributes via react, too. If I have a, for example, a success and an error button I want to apply a different background color to them.
Right now, I'm doing this with jQuery's extend function:
<span style={$.extend({background: 'forestgreen'},this.state.buttonStyle)}></span>
But I'm wondering if there is a better and maybe more readable solution for this. Any advice?
Share Improve this question asked Jul 22, 2015 at 16:14 baaobaao 73.4k18 gold badges150 silver badges207 bronze badges1 Answer
Reset to default 7If you use a transpiler that implements the spread property proposal (such as Babel), you can write
style={{...this.state.buttonStyle, background: 'forestgreen'}}
instead.
Whether thats "better" or more readable is likely subjective.
本文标签: javascriptExtending style object in reactjsStack Overflow
版权声明:本文标题:javascript - Extending style object in react.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744570878a2613331.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论