I am encountering an issue with importing a .css stylesheet in a basic react app. I have the following components:
AvatarHeader.js:
import styles from './AvatarHeader.css';
export default function AvatarHeader({ style, children }) {
return (
<div>
<img style={styles.image} src={Background} alt="background">
{ children }
</img>
AvatarHeader.css:
.image {
width: 400
}
Both AvatarHeader.js and AvatarHeader.css are located in the same folder.
package.json:
{
"name": "UtWeb",
"version": "0.1.0",
"private": true,
"devDependencies": {
"css-loader": "^0.25.0",
"react-scripts": "0.9.0",
"webpack": "^2.2.1",
"webpack-dev-server": "^1.9.0"
},
"dependencies": {
"react": "^15.4.2",
"react-dom": "^15.4.2",
"react-redux": "^4.3.0",
"react-router": "^2.0.0",
"redux": "^3.2.1",
"react-router-redux": "^4.0.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
The styles are not being applied to the component, but it works if I modify AvatarHeader.js as follows:
import styles from './AvatarHeader.css';
const image = {
width: 400
}
export default function AvatarHeader({ style, children }) {
return (
<div>
<img style={image} src={Background} alt="background">
{ children }
</img>
I am unsure how to resolve this issue and make use of the initial method of importing the css file.