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.

withStyle access to component props

See original GitHub issue
  • This is a v1.x issue.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

Is the currently an api to accessing the component props from the style like styled-components? say something like this:

const styles = (theme, props) => ({
    root: {
        display: 'flex',
        flexDirection: 'row',
        backgroundImage: `url("${props.url}")`,
        backgroundColor: props.color? props.color : theme.pallete.primary.main
    }
})

const Hero = ({classes, title}) => <div className={classes.root}>{title}</div>

export default withStyle(styles)(Hero)

Current Behavior

I’m currently using inline styling

Example

const styles = (theme, props) => ({
    root: {
        display: 'flex',
        flexDirection: 'row'
    }
})
const genStyle = (url, color='blue') => ({
    backgroundColor: color,
    backgroundImage: `url("${url}")`
})

const Hero = ({classes, title, url, color}) => (
    <div className={classes.root} style={genStyle(url, color)}>
        {title}
    </div>
)

export default withStyle(styles)(Hero)

Context

Generate styles based on the props of the component like determining theme, passing in background colors etc.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
oliviertassinaricommented, Sep 3, 2018

@mfoncho The issue is still open. It’s one of my top priorities. I also want to look into emotion at the same time, see if we can leverage it.

0reactions
mfonchocommented, Sep 10, 2018

@JacquesBonet not so much of a library is needed to implement the required feature but just a simple like this StyledPropsHOC

Read more comments on GitHub >

github_iconTop Results From Across the Web

withStyle access to component props · Issue #12768 - GitHub
Is the currently an api to accessing the component props from the style like styled-components? say something like this: const styles = (theme ......
Read more >
Passing props to MUI styles - reactjs - Stack Overflow
In MUI v5, this is how you access the props when creating the style object ... When you're using withStyles , you have...
Read more >
How to use the @material-ui/core.withStyles function in ... - Snyk
withStyles examples, based on popular ways it is used in public projects. ... withStyles(styles)(RenderComponentsRaw); let components = (props: stateProps) ...
Read more >
Advanced (LEGACY) - MUI System
The wrapped component accepts a classes prop, it simply merges the class names provided with the style sheet. const Nested = withStyles({ root:...
Read more >
Basics - styled-components
Simple dynamic styling: adapting the styling of a component based on its props or a global theme is simple and intuitive without having...
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