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.

Add official support for createStyled?

See original GitHub issue

I was wondering if this library could provide (or if it already does) a component that would allow to use styles with a render prop pattern, instead of the withStyles HOC.

I searched for it, and the best I could find was this, but that’s not quite what I would’ve expected. That option would need users of this api to create a new component every time:

import { createStyled } from '???';

const Styled = createStyled({ /* styles go in here */ })

// It is supposed to be used like this:
render() {
  return (
    <Styled>
      {({ classes }) => (
        // render your thing here
      )}
    </Styled>
  );
}

I wonder if it would be a bit better or even possible to have a generic component that receives styles and provides classes, instead of having to create one component tied to specific styles:

// would be something provided by this lib
import Styled from 'material-ui/Styled';

const styles = { /* styles go in here */ }

// Then use it like this:
render() {
  return (
    <Styled styles={styles}>
      {({ classes }) => (
        // render your thing here
      )}
    </Styled>
  );
}

Also, as a side note, even if this suggestion is not accepted, I wonder why the createStyled helper is not provided as an export of this library, just as withStyles is.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
oliviertassinaricommented, Apr 17, 2018

@gnapse I’m reopening as it’s a good question. I don’t have a definitive answer.

1reaction
oliviertassinaricommented, Apr 17, 2018

why createStyled (as it appears here) isn’t provided by this library out of the box, just as withStyles is?

@gnapse The initial motivation was: it’s working, but it’s an extra API to support. Let’s document it and see how it’s used in the wild. Now, as people start using it and rely on it in production with no issue, I’m more confidence integrating it into the core. I have no real objection to it. It just hasn’t been a priority so far. You know, extending the API comes with overhead: documentation, tests, maintenance, etc.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add official support for createStyled? · Issue #11047 - GitHub
I was wondering if this library could provide (or if it already does) a component that would allow to use styles with a...
Read more >
styled() - MUI System
It supports the theme's styleOverrides and variants to be applied, based on the name applied in the options (can be skipped). It adds...
Read more >
Advanced Usage - styled-components
styled-components has full theming support by exporting a <ThemeProvider> wrapper component. This component provides a theme to all React components ...
Read more >
Using Styled Components - Expo Documentation
Using styled-components with Expo, you can create universal styles that'll work the same across web, mobile, and desktop! Getting Started. Install the Styled ......
Read more >
Theme with styled-components and Typescript - Medium
This will help with IntelliSense and ensure a contract for all available themes. // styled.d.ts import 'styled-components';interface IPalette {
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