Use CSS in React

Follow challenges in React i took here, i decided to build the environnement on my own following those steps

  1. install Nodejs
  2. Launch cmd then type npx create-react-app my-app-name
  3. then type npm start to launch the app.

I have create some components and practise successfully but things got messy when i noticed that my CSS code doesn’t work whenever i import them (import './style.css).

I been searching on google, they been telling me a lot of stuff. they asked me to install many things with command prompt like css-loader and style-loader with this command: $ npm install css-loader style-loader --save-dev and put some configurations in a file name webpack where i don’t find anywhere in my React app.

Can you help me find out what to do exactly?? If ever you can, i’ll greatly appreciate because i have been searching this for a while in the internet.

Hi,
it seems to me that your css file and Header.js file are not in the same folder.
So try this:

import '../style.css'

Basically the two points allows you to move to the “upper” folder, in this case from the “components” folder, where the Header.js file is located, to the “src” folder, where style.css is located.

Usually, when in your terminal you get an error like “Module not found”, it means that your import statement is wrong

1 Like

To my great surprise, It worked!
Thanks a lot for your help!!!