13

Can I use CSS for styling my ReactNative component. Currently I can only use StyleSheet like this:

var styles = React.StyleSheet.create({
 autocomplete: {
   backgroundColor: '#FFF',
   zIndex: 5,
 },
 ...

I want to use CSS instead of this as in ReactJs

2

5 Answers 5

7

First create a file named App.module.css

then write your pure css here

.container {
  background-color: rgb(44, 0, 95);
  width: 100%;
  height: 100%;
}

then,

import the file in your js file

import style from './App.module.css';

Now you can this style like normal react native styling

<View style={style.container}>
Sign up to request clarification or add additional context in comments.

2 Comments

Great approach! But when I do this I get the following error: "None of these files exist: * components/App.module.css(.native|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json)" It looks like I can't import a file which ends in .css?
I get the same thing
0

What do you mean pure css ?

Have a look at styled-components, the project is in active development.

This allow you to style your react components using css.

1 Comment

I mean just css.
0

I had the same issue once and I solved it using this component. I see is no longer under development however for me it was perfectly working.

What it does basically is taking your CSS files and it will generate from them some StyleSheet components that you can easily integrate in your react application.

Comments

0

Try this library: https://atom.io/packages/atom-react-native-css

You can style components with CSS and built in support for SASS.

Comments

0
<Text style={{backgroundColor:'#FFF',zIndex: 5}}></Text>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.