Using React and classnames to do styles. I get no errors but I get undefined when I console.log(styles.uiPad). I do get an object when I console.log(styles). My classnames import component also gets console.logged successfully but nothing happens. What am I doing wrong? Is this a webpack thing?
Here are my imports:
import styles from '../assets/stylesheets/base.scss'
import classNames from 'classnames'
This is my render:
<div className={classNames(styles.uiPad)}></div>
You are importing a Sass file. You need to compile Sass into CSS before importing it.
Related
I am facing problem with external css files on my react project. I am using material UI components. In the react components folder I created css file for each components but they are not loading when i hard reload the site.
I wanted to use external css rather than styled components or material ui style syntax.
Just import the css / scss file in your component and make sure you've added the classes for the elements.
If you are looking a more generic option you can import your style.css file in your main App.jsx (if you call it "App.jsx") file. Then you just use the className and will have access to your css.
App.jsx file
import './style.css'; // Your path to your style.css
function App() {
return (
<div>React app</div>
);
}
export default App;
I'm building a website with gatsby and I have set up the gatsby scss plugin. Everything seemed to be working fine until I realized my styles from home.module.scss were also being applied to my navigation component that only imports navbar.module.scss.
I have a style for my buttons in each of these modules that looks like this...
button {
// different styles in the different modules
}
Both of these modules import a global scss file at the top like this...
#import '../styles/global.scss';
The react components only import their respective modules. In my main index component I import global styles like this import './global.scss'
Am I misunderstanding how scss modules work in React or is this is a bug?
from my understanding
In react importing SCSS or CSS in any component will be global.
So it will affect all other components as similar to the component where you imported the SCSS file.
use different class names
What is the purpose of using createGlobalStyle instead of just importing a css file, when working with styled components?
I have read the docs, but i don't get it..
When I add new HTML code to my React app , the CSS styles from the App.css file aren't applying anymore , until I retype Import './App.css'" in the head.
Any solution please.
All our components in React act like modules and have their data (variables, functions) private to them. To access code or styles from other files we need import from other modules.
Our App.js is also one such component. Until you do import './App.css', the CSS will not be applied to App.js.
Problem solved , it was about bootstrap .
Import bootstrap/dist/css/bootstrap.min.css before App.css .
I was doing the opposite .
I am very new to UI libraries and CSS in React. I'm using a data picker from Ant Design: https://ant.design/docs/react/introduce.
They provide CodePen examples and in the CSS tab you can see this:
#import 'antd/dist/antd.css';
However, when I add this to my CSS stylesheet which I import in to the component using import './Component.css'; I get the error
Module not found: Can't resolve './antd/dist/antd.css'
in the components folder.
I have installed the npm package but can't get the CSS to work.
What am I doing wrong?
Make sure antd is installed correctly and it's visible in your package.json it should be there
"antd": "3.19.2" assuming you ran npm i antd
as well as importing it in your component with
import { DatePicker } from 'antd';
Then import the style manually in your component
import 'antd/dist/antd.css';