Gorgorita32 Gorgorita
Gorgorita32 Gorgorita

Reputation: 119

How to connect reactjs file with css

I don't have a huge website, but I still want to maintain css separate from my js files.

My folder structure:

static
    css
        style.css
    js
        landing.js

In my landing.js file, I have: import styles from '../css/style.css';

With the above mentioned setup, I am getting this error: react-dom.production.min.js:12 Uncaught Error: Minified React error #130;

Am I doing something wrong? If I must use something like webpack to avoid getting minified errors, why is that the case? Why can't I just use simple CSS?

Note: I'm not using JSX

Upvotes: 1

Views: 237

Answers (3)

rozalex
rozalex

Reputation: 330

Link the css file from your main html file where you have the root div of your app.

Upvotes: 2

Muneeb
Muneeb

Reputation: 1559

Instead of importing it in styles just include your css like this

import '../css/style.css'; // ES5
require('../css/style.css'); 

later after compilation it will become part of your build.

Upvotes: 0

Artem Mirchenko
Artem Mirchenko

Reputation: 2170

For importing css in .js files in reactJs env you need to set up css-loader.

But if you don't want to play around with webpack or other bundlers, include your css in html file for now.

Other variant is write inline css in your React component, or use stylesheets like Radium.

Upvotes: 1

Related Questions