简体   繁体   中英

how to call a component into anther in reactjs

I cannot import mystyle.css file stylesheet.css in react kindly anyone tell me to set the path in react I want to call myStyles.css file into main stylesheet.js using this import mystyles from '../components/myStyles.css' but I received an error form the browser like this

./src/components/Stylesheet.js

Module not found: Can't resolve './src/components/myStyles.css' in 'E:\ReactJS\my-app\src\components'

can anybody tell me how to include this file into my Stylesheet.js file

try: ../ instead of./

or try placing the file in the public folder and calling from there. I had a similar issue that was helped this way.

you're sure you specified the file path correctly, right? react js may not automatically select your css file. Make sure you give it the right name.

in the Stylesheet.js file:

import '../components/myStyles.css' // sure you're calling it the right way from the right place 

if the problem is still not resolved, we can examine the files as code snipped.

If you want to import css file to the component, you should do it this way:

import './myCss.css';

instead of

import myCss from './myCss.css';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM