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.

Multiple withStyles only rendering the first

See original GitHub issue

I asked this on Gitter originally, but I’m struggling to get the following to work (example):

import appStyles from './App.scss`;
import otherStyles from '../OtherComponent/otherStyles.scss';

...

export default withStyles(App, appStyles, otherStyles);

This doesn’t throw any errors, and both the styles are within the styles array, only the appStyles are loaded in.

Is this the correct way of going about this?

Issue Analytics

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

github_iconTop GitHub Comments

5reactions
koistyacommented, Apr 18, 2016

I guess, we need to create <StylesContext> (or <StylesProvider>) React component, that can be used to set insertCss context variable…

2reactions
frenzzycommented, Apr 18, 2016

Your context insertCss function should handle all style arguments rather than just one, for example:

// client.js
const context = {
  insertCss(...styles) { styles.forEach(style => style._insertCss()); },
};
// server.js
const css = [];
const context = {
  insertCss(...styles) { styles.forEach(style => css.push(style._getCss())); },
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

Material UI withStyles on multiple styled HoCs - Stack Overflow
My application uses HoCs for its modals and I use withStyles to style them, when I apply multiple HoCs to one component however...
Read more >
Pages render without styles for a brief second #15642 - GitHub
Bug report Describe the bug Pages render without any styles for a brief second before the CSS is loaded: This only happens in...
Read more >
JSS integration with React
Static properties being rendered first so that function values will have higher source order specificity. import React from 'react' import withStyles from ...
Read more >
Rendering Elements - React
Applications built with just React usually have a single root DOM node. ... To render a React element, first pass the DOM element...
Read more >
Advanced (LEGACY) - MUI System
The makeStyles (hook generator) and withStyles (HOC) APIs allow the creation of multiple style rules per style sheet. Each style rule has its...
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