question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JSS plugins customisation and global styles [@next]

See original GitHub issue

@oliviertassinari sorry to bother… I’m trying to apply global rules I have defined in a NPM package @damianobarbati/jss-reset to the app but I don’t find in the docs how to directly use the jss instance MUI is using. Docs say Material-UI is using the jss-preset-default module. You can always add new plugins if needed: but how? 🤔

I also tried to apply globals in a random app component:

const styleSheet = createStyleSheet('List', theme => ({
    '@global': {
        body: {
            margin: 0,
            padding: 0,
        },
    },
    root: {

And I tried to apply globals in the theme creation:

const theme = createMuiTheme({
    '@global': {
        body: {
            margin: 0,
            padding: 0,
        },
    },

Does not seem to work.

For reference I’m using this in an another app (react-jss@latest ~ 1.7):

import React from 'react';
import ReactDOM from 'react-dom';

import { create as createJss } from 'jss';
import { JssProvider } from 'react-jss';
import preset from 'jss-preset-default'
import reset from '@damianobarbati/jss-reset';
//const App = blablabla
const jss = createJss(preset());
jss.createStyleSheet(reset).attach();

ReactDOM.render(<JssProvider jss={jss}><App /></JssProvider>, document.getElementById('app'));

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

12reactions
richburdoncommented, Dec 14, 2017

OK figured it out (often takes writing an issue to do that). @damianobarbati this might be useful to you but I’m sure you’ve figured it out already. You don’t need to use customs JSS.

Add @global defs to a style (not theme) then style your root element.

const styles = (theme) => ({
  '@global': {
    'a': {
      'color': 'red' .    // Make all links red.
    }
  }
});

const Main = (props) => {
  return (
    <a>Hello</a>
  );
}

const AppRoot = (props) => {
  return (
    <MuiThemeProvider theme={ theme }>
      <Main/>
    </MuiThemeProvider>
  );
};

const AppRootWithStyles = withStyles(styles)(AppRoot);

ReactDOM.render(<AppRootWithStyles/>, document.getElementById(rootId));
6reactions
corytheboydcommented, Aug 25, 2017

@oliviertassinari

You gonna need to do something like:

Please add this example code to the documentation for Customization > CSS in JS. It mentions the JssProvider but does not mention how it fits into the MuiThemeProvider at all.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSS plugins customisation and global styles [@next] #7430
I'm trying to apply global rules I have defined in a NPM package ... JSS plugins customisation and global styles [@next] #7430.
Read more >
Basic Features: Built-in CSS Support - Next.js
Next.js supports including CSS files as Global CSS or CSS Modules, using `styled-jsx` ... For example, consider the following stylesheet named styles.css :...
Read more >
Global vs. Local Styling In Next.js - Smashing Magazine
The answer is surprisingly simple — to write well-structured CSS that balances global and local styling concerns.
Read more >
JSS integration with React
Install; Basic; Dynamic Values; Prefix classname; Theming; Accessing the theme inside the styled component; Accessing the theme without styles; Using custom ...
Read more >
Global Styles in Next.js - Netlify
CSS Modules, Styled JSX, Sass, Less, Stylus, Styled Components, Emotion... I could go on! If you want to style a component, Next.js has...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found