-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
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
this.context.muiTheme is undefined #686
Comments
Same here: #682 I can't make it work either :( |
See https://github.com/callemall/material-ui/blob/master/example/src/app/components/main.jsx#L5-L24, you have to add it manually now. |
I did add it. Then I had: |
@wmertens That really helped!
However, I'm still somehow getting the same error, when using, for example, RaisedButton. Upon some investigation, I found that within What could be causing this? |
Figured it out. This is probably not relevant for most people, but here's more info: I'm using browserify and browserify-shim to bundle scripts. The shim transform wasn't set to global, so when a package in node_modules required react (like material-ui, in this case), the shim isn't applied and the whole library is inlined. |
@SebT I'm seeing the same, I have a component that simply adds this.props.children to its createElement call and it looks like they lose their context then. No time to investigate right now |
@SebT: context seems to suck: acdlite/flummox#70 (comment) @super-cache-money facebook/react#1939 strikes again |
@SebT I solved it for me with this non-perfect solution (CoffeeScript): Instead of using There are several things wrong with that, it should really use the ReactChildren iteration and it shouldn't replace the key if one is there, but in my case that doesn't matter and probably won't until 0.14 comes out. |
Well I tried again yesterday and this time it did work with childContext. I don't really know what happened, I re-ran a Anyway, thanks for the help @wmertens ;) |
@super-cache-money - I might have a similar issue which I am unable to solve. I am using webpack to convert the material-ui library and use it in the browser. I think that inlines the react library in that file itself. Now I also have an external reference to a react library from my main html file <script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.3/react.js"></script> Is this why this conflict is happening ? Any way to work around it ? |
I will post how I solved this problem: I was including 'react/addons' in my vendors bundle file using browserify. However in my components I was requiring react in this way: import React from 'react'; (not 'react/addons') Once I changed 'react/addons' to 'react' in my vendors bundle file, error dissapeared. |
I still can't make this to work. I use react-router@1.0.0-beta3 and my router is like
I've already define getChildContext() in App component
in somePage component I use some material UI components, and I get this warning
and this error
it was because this.context.muiTheme is undefined. What else do I have to do? |
Use React 0.14 beta or clone the children. On Sun, Aug 23, 2015, 08:14 Qrysto notifications@github.com wrote:
Wout. |
now the problem is
when i try to install react@0.14.0-beta1 😆 . Btw what do you mean by "clone the children"? |
you can drop the tap-event plugin in react 0.14 I think :) when you clone the children, they get a new owner (you) and the context works. See #686 (comment) |
Oh, the plugin is needed until React 1.0: https://github.com/zilverline/react-tap-event-plugin |
@wmertens thanks for the help. What exactly do you mean by cloning the children? @Qrysto I have this problem when I try to upgrade to react 0.14 beta. How are you solving it?
|
@sathify actually I haven't solved it yet 😆 Probably I'll ready more about that "cloning the children" when I have time, but I wonder how people can still use MUI at the moment ❓ |
Having the same problem with react-router@1.0.0-beta3, right now don't know if that is the cause of the problem |
I upgraded to react@0.14.0-beta3 and the problem went away for me. Don't need react-tap-event-plugin (gives an error) and had to edit the node_modules/material-ui/package.json to remove the peerDependency. Messy workaround for that, but works. @sathify YMMV with those fluxible peerDependencies. |
@Vijar This is what I was talking about - any chance the fluxible modules work with |
@sathify I don't think you need to upgrade to React0.14 to get material-ui to work. If you're using provideContext with fluxible you can just do this: Application = provideContext(Application, {
muiTheme: React.PropTypes.object
}); Then for actually setting the child context properly use this gist as a plugin and plug it into your fluxible app. After that, everything should work. Maybe open an issue on fluxible repo if you want to talk about this some more. |
This is an issue of react-router 1.0.0, here is a workaround: |
@sathify as far as fluxible + material-ui: https://github.com/Vijar/fluxible-plugin-material-ui |
@Vijar thanks. This seems like a better way to do it with fluxible, plugging the context. I however just initiallized in the root component. |
I confirm that the issue disappear when using React 0.14.0 (-rc1) |
I get that React 0.14 solves this, but I'm confused at how to update to that when the current material-ui module does not support it as a dependency. Tried -f to no avail. |
import getMuiTheme from 'material-ui/styles/getMuiTheme'
...
static childContextTypes =
{
muiTheme: React.PropTypes.object
}
getChildContext()
{
return {
muiTheme: getMuiTheme()
}
} |
@halt-hammerzeit where should I put this? In my scenario, I'm using Material-UI and trying to test it with Enzyme. But for my components do work properly I have to render them with |
@rafaeleyng I got this working with shallow, but not mount yet. Helper function: import { getMuiTheme } from 'material-ui/styles';
const muiTheme = getMuiTheme();
export const shallowWithMuiThemeContext = node =>
shallow(node, { context: { muiTheme } });
// For traditional react-test-renderer usage:
export const createWithMuiTheme = node =>
renderer.create(React.createElement(MuiThemeProvider, null, node)); Example usage in unit test: const myComponent = shallowWithMuiThemeContext(<MyComponent />);
myComponent.instance().funcThatChangesState(expectedStateChangeObject);
expect(myComponent.state('stateObjectFieldSetByAboveFunc')).toBe(
expectedStateChangeObject
); |
The docs are updated.
|
I wonder which level to put
Now I put it in
but got
if I write like
still got
|
Provide |
@catamphetamine Isn't there a default theme already ? |
@eromoe dunno, not using this library |
I've tried to use 0.8 with both React 13.3 and React 13.1.
I've tried a few components, including RaisedButton, and Checkbox.
As the title states, rendering breaks with the following error:
muiTheme
is undefined.I've triple checked my node_modules directory; there's only one version of react in there.
There are no warnings, other than this old one:
Warning: bind(): React component methods may only be bound to the component instance. See exports
Inserting this:
gives the following warning:
Failed Context Types: Required context
muiTheme
was not specified inMyOtherwiseWorkingComponent
. Check the render method ofexports
.I'm so eager to try this out! What could be the issue here?
The text was updated successfully, but these errors were encountered: