react领域里面jsx中的style的值为什么放到了{}中

我的疑问是:
jsx中的style为什么不是像html中写字符串?而是使用javascript object?
同类提问:
关于 React 为什么使用 JS Object 代替 CSS 来创建样式?

答案:
我的感觉是动态和灵活。很高兴我能在搜索答案之前想到这一点。
基于字符串修改css和基于javascript Object修改css的难度根本不再一个级别。
来自react文档的说明:
The style attribute accepts a JavaScript object with camelCased properties rather than a CSS string. This is consistent with the DOM style JavaScript property, is more efficient, and prevents XSS security holes.

这几篇文章读完,基本上就能解答了。
https://reactjs.org/docs/dom-elements.html#style
https://speakerdeck.com/vjeux/react-css-in-js?slide=2
https://www.ruanyifeng.com/blog/2017/04/css_in_js.html


一门技术的发展,并非是技术的发展,本质上是多方博弈的结果,例如使用者的数量,商业利益上的考量等等因素

posted @ 2022-03-06 10:38  叶常落  阅读(33)  评论(0编辑  收藏  举报