-
Notifications
You must be signed in to change notification settings - Fork 27k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Context does not apply through <Main /> #873
Comments
@Ehesp can I have a sample repo. So, I could work on this pretty fast. |
Sure, should hopefully be able to slap something up in the next couple of
hours.
On 24 Jan 2017 7:53 pm, "Arunoda Susiripala" <notifications@github.com> wrote:
@Ehesp <https://github.com/Ehesp> can I have a sample repo. So, I could
work on this pretty fast.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#873 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAzZXiaxLrsVrtxGgaZyea1Z3e7EK3pJks5rVlacgaJpZM4Lsscv>
.
|
@arunoda Here you go: https://github.com/Ehesp/next-mui-context Install modules and just In Index, if you comment out |
@Ehesp hey, I checked it and unfortunately that's something you can't do. Actual, Next.js app is runs inside the So, you need to provide your MUI context in the page's render method. |
Also there's a problem with the SSR when doing styles. Check the console. Here's a easy and ugly fix: mui/material-ui#3009 (comment) But here's the proper way to do it: import React from 'react';
import RaisedButton from 'material-ui/RaisedButton';
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
import getMuiTheme from 'material-ui/styles/getMuiTheme';
import darkBaseTheme from 'material-ui/styles/baseThemes/darkBaseTheme';
export default class extends React.Component {
static getInitialProps = ({ req }) => {
const userAgent = req? req.headers['user-agent'] : navigator.userAgent
return { userAgent }
}
render() {
const { userAgent } = this.props
return (
<div>
<MuiThemeProvider muiTheme={getMuiTheme(darkBaseTheme, { userAgent })}>
<div>
<p>Render a styled MUI Button: </p>
<RaisedButton label="Button" primary style={{ margin: 12 }} />
</div>
</MuiThemeProvider>
</div>
);
}
} |
I use material-ui in my app. I created a layout component that will just wrap whatever is passed into the layout component with the theme provider. Is that what your trying to accomplish? |
Hey. Thanks for checking that out.
That's fine then, I'll make a decorator to contain each of the pages. I'm
assuming this is going to be the same as Redux then using Provide.
Cheers
…On 25 Jan 2017 3:25 am, "Tyler Knipfer" ***@***.***> wrote:
I use material-ui in my app. I created a layout component that will just
wrap whatever is passed into the layout component. Is that what your trying
to accomplish?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#873 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAzZXjsgrkktK37JGYjglSTNAbMW4T9Pks5rVsCkgaJpZM4Lsscv>
.
|
For those interested, here's the solution we took, handles both Redux & Material-UI:
Every page is wrapped in a
This now provides Redux & MUI throughout every page. It also allows the actual page file to use
These are then applied into the props of the contained page/component. |
@arunoda should we create an example showing how to use material-ui with next.js? We've had questions about material-ui multiple times 😄 |
@timneutkens why not :) |
Hey @arunoda, really like the library but this is a main issue in my opinion. |
A solution that I just wrote and havent fully tested out but seems to be working is
then my page can be exported
|
Hello,
I'm currently using material-ui in my app. I'm taking advantage of
pages/_document.js
, along with<Main />
:Then the page being loaded:
So normally, the context would be passed through and I'd have access to the theme properties, and so would any material-ui components. However, in this case the context is not being applied.
Logging out the context in the
Main
source code works.The text was updated successfully, but these errors were encountered: