Importing CSS files in Isomorphic React Components

前端 未结 10 1284
失恋的感觉
失恋的感觉 2020-11-30 22:01

I have a React application with Components written in ES6 - transpiled via Babel and Webpack.

In some places I would like to include specific CSS files with specific

10条回答
  •  眼角桃花
    2020-11-30 22:33

    If you're building an isomorphic app with ES6 and want to include CSS when rendering on the server (important so basic styles can be sent down to the client in the first HTTP response) check out the @withStyles ES7 decorator used in React Starter Kit.

    This little beauty helps ensure users see your content with styles when the page is first rendered. Here's an example isomorphic app I'm building leveraging this technique. Just search the codebase for @withStyles to see how it's used. It goes a little something like this:

    import React, { Component, PropTypes } from 'react';
    import styles from './ScheduleList.css';
    import withStyles from '../../decorators/withStyles';
    
    @withStyles(styles)
    class ScheduleList extends Component {
    

提交回复
热议问题