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.

withWidth does not pass theme prop further

See original GitHub issue

When wrapping withWidth with withTheme, theme property does not appear. I checked the source and I believe this is because of that line https://github.com/mui-org/material-ui/blob/f46b77827cbecad926eb113bad0fb6a695f94e40/src/utils/withWidth.js#L84

I suppose it should check somehow if theme prop should be passed further.

I’m using 1.0.0-beta.24 version.

Here is a small example of the issue (typescript)

function Test(props: WithTheme) {
    return (
        <div>
            {JSON.stringify(props)}  // no theme property here
        </div>
    );
}

let MobileDialog = withWidth()<WithTheme>(Test);
let WTheme = withTheme()(MobileDialog);

class App extends React.Component {
    render() {
        return (
            <div className="App" style={{padding: 16}}>
                <WTheme/>
            </div>
        );
    }
}

Issue Analytics

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

github_iconTop GitHub Comments

5reactions
CharlieIGGcommented, Sep 15, 2018

I thinkI figured it out, I needed to pass props like so:

export default withMobileDialog<Props>()(InformationDialog);

0reactions
jflord78commented, Nov 27, 2018

@CharlieIGG, thanks, this saved me a ton of aggravation 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

withWidth does not pass theme prop further #9538 - GitHub
I suppose it should check somehow if theme prop should be passed further. I'm using 1.0.0-beta.24 version. Here is a small example of...
Read more >
Passing props to MUI styles - reactjs - Stack Overflow
Solution for how to use both props and theme in material ui : const useStyles = props => makeStyles( theme => ({ div:...
Read more >
Advanced Usage - styled-components
You can also pass a function for the theme prop. This function will receive the parent theme, that is from another <ThemeProvider> higher...
Read more >
Theming in React with Styled Components | by Ross Bulat
This documentation should not be confused with styled-theming . The section does however demonstrate how we can use props to pass theme styles...
Read more >
Advanced (LEGACY) - MUI System
Add a ThemeProvider to the top level of your app to pass a theme down the React component tree. Then, you can access...
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