React Native External Stylesheet

2020-05-24 20:51发布

Is there a way in React Native that I can put all of my styles in a single file so it can easily be maintained (from my perspective) like in HTML we have a .css file.

And also I have a module where there are different styles based on a current user.

8条回答
时光不老,我们不散
2楼-- · 2020-05-24 21:37

You could add this module to your pipeline, and create a Gulp, or Webpack task to transpile the CSS into JavaScript.

https://github.com/sabeurthabti/react-native-css

In my experience you're best of not using the same CSS for web and react native, because React Native's stylesheets don't actually cascade.


Or if you're willing to change your pipeline a little bit, PostCSS, which is a CSS4 to CSS3 transpiler, which supports all the features of SASS, can also be used to transpile, CSS to JavaScript

https://github.com/postcss/postcss-js

查看更多
smile是对你的礼貌
3楼-- · 2020-05-24 21:41

You can try my project rn-less.

It isolates your stylesheet from your jsx/js files with less.js.

And I have a VS Code extension for it, with which you can jump between .less files and .js/.jsx files easily.

enter image description here

查看更多
登录 后发表回答