#Hey guys, how do i connect css to react?

18 messages · Page 1 of 1 (latest)

hollow trail
#

In your index.js file add the css as an import like this:

import './style.css'
unborn charm
#

like this?

hollow trail
#

The import path needs to be relative.

unborn charm
#

because it shows an error

hollow trail
#

Have you learned about import relative paths yet?

unborn charm
#

no
not yet

hollow trail
#

Ok, imagine you are in the index.js file. You have to move from that file, to the App.css file to create the path. If you want to look in the current folder, you use ./ If you want to go up a level in the folder structure, you use ../

So in this case, we need to go up a level, then into views, then select the file, so we do this:

import '../views/App.css'
unborn charm
#

okay thank you alot!

hollow trail
#

👍

unborn charm
#

so should i just move it in?

hollow trail
#

Put all the css inside your src folder @unborn charm

#

All code that you write should go in src

unborn charm
#

so everything should basically be in source? can i create sub folders tho?

hollow trail
#

create subfolders but everything you write should be in src

unborn charm
#
/views/App.css'```  and this is how i should import it if all the css files where in the sub forlder
hollow trail
#

If the views folder is inside src, then you just need to do import './views/App.css'

unborn charm
#

Okay thank you alot for your
patience