Style in React

发布时间:2019-08-05 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了Style in React脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

前端模块化之后,CSS也能向模块一样导入, 之前提倡JS 与CSS分离,现在JS和CSS混合的方式又开始流行了。

CSS与JS分离

CSS Modules

  • No more conflicts 没有名称冲突
  • No global scoPE
  • Composing From other files
  • Composing from global class names

Style in React

Style in React

CSS in JSS

JSS

  • Theming 利用 ThemePRovider 和 theme 封装组件
  1. wIThTheme

Style in React

  1. ThemeProvider

Style in React

Benefits

  • Theming support out of the box.
  • Critical CSS extraction.
  • Lazy evaluation - sheet is created only when component will mount.
  • Auto attach/detach - sheet will be rendered to the DOM when component is about to mount and will be removed when no element needs it.
  • A Style Sheet gets shared between all elements.

Styled-component

  • 通过props 修改style

Style in React

  • extend 继承

Style in React

  • Theming
  1. styled-components has full theming support by exporting
  2. a&nbsp;<ThemeProvider> wrapper component. 
  3. Function themes
  4. Getting the theme without styled components

Style in React

styled-component 上提供了个对比 https://github.com/styled-com...

参考文献
https://glenmaddern.com/artic...
https://speakerdeck.com/vjeux...
http://www.alloyteam.com/2017...
https://hackernoon.com/the-co...

脚本宝典总结

以上是脚本宝典为你收集整理的Style in React全部内容,希望文章能够帮你解决Style in React所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。