Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native External Stylesheet

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.

like image 795
Sydney Loteria Avatar asked Nov 08 '15 15:11

Sydney Loteria


People also ask

Can you use CSS files in React Native?

React Native lets you style your whole application using JavaScript. Every component can use a prop named style , which enables you to write CSS styles for those components. There are two main methods that React Native has for creating styles: inline styling and using a style prop to style subcomponents.

Why StyleSheet is used in React Native?

A StyleSheet is an abstraction similar to CSS StyleSheets. Instead of creating a new style object every time, StyleSheet helps to create style objects with an ID which is further used to reference instead rendering it again.


1 Answers

You could simply create a Styles component like so with all your styles...

import { StyleSheet } from "react-native"  export default StyleSheet.create({    ... }) 

Then on any view needing styles, simply require it...

import styles from "./Styles" 
like image 71
Chris Geirman Avatar answered Sep 23 '22 21:09

Chris Geirman