How to apply CSS and Styling to a React component

后端 未结 7 697
梦如初夏
梦如初夏 2020-12-08 06:19

I have been looking, however, I have had little luck finding any way to style the React.js file that I have created, I converted it from a standard web page, so I have the o

7条回答
  •  不思量自难忘°
    2020-12-08 07:05

    I use Sass (.scss) to style my React components. I have also used PostCSS. And they are also modularized. Once you have it set up via your workflow (I use webpack), all you need to do to style your React app is to import the style.scss (yes, .scss) which contains your imported partials etc into your index.js file which resides in root along with your main App.js. That's where everything else you need in order to make your app work resides as well. For example, this is what mine looks like for the React app I am working on now:

    Index.js:

    import React from 'react';
    import ReactDOM from 'react-dom';
    import 'core-js/es6/map';
    import 'core-js/es6/set';
    import App from './App';
    import './favicon.ico';
    import './style/style.scss';
    
    ReactDOM.render(
        , document.getElementById('root')
    );
    

提交回复
热议问题