admin管理员组文章数量:1336169
import React, { Component } from 'react';
import './App.css';
import Screen from './ponents/Screen/Screen';
import Button from './ponents/Button/Button';
import { MuiThemeProvider, createMuiTheme } from 'material-ui/styles';
import pink from '@material-ui/core/colors/pink';
const buttonTheme = createMuiTheme({
palette: {
primary: {
main: '#2dff46',
},
secondary: pink,
}
});
class App extends Component {
render() {
return (
<MuiThemeProvider theme={buttonTheme}>
<Screen>
<div>Hello</div>
<Button variant='contained' color='primary'>
GO
</Button>
</Screen>
</MuiThemeProvider>
);
}
}
export default App;
I am simply trying to create a button with some custom colors (theme). It will work without "theme={buttonTheme}" but of course it uses the default. I get the following error:
TypeError: Cannot read property 'borderRadius' of undefined
styles
node_modules/@material-ui/core/Button/Button.js:41
38 | minWidth: 64,
39 | minHeight: 36,
40 | padding: '8px 16px',
> 41 | borderRadius: theme.shape.borderRadius,
42 | color: theme.palette.text.primary,
43 | transition: theme.transitions.create(['background-color', 'box-shadow', 'border'], {
44 | duration: theme.transitions.duration.short
thanks!!
import React, { Component } from 'react';
import './App.css';
import Screen from './ponents/Screen/Screen';
import Button from './ponents/Button/Button';
import { MuiThemeProvider, createMuiTheme } from 'material-ui/styles';
import pink from '@material-ui/core/colors/pink';
const buttonTheme = createMuiTheme({
palette: {
primary: {
main: '#2dff46',
},
secondary: pink,
}
});
class App extends Component {
render() {
return (
<MuiThemeProvider theme={buttonTheme}>
<Screen>
<div>Hello</div>
<Button variant='contained' color='primary'>
GO
</Button>
</Screen>
</MuiThemeProvider>
);
}
}
export default App;
I am simply trying to create a button with some custom colors (theme). It will work without "theme={buttonTheme}" but of course it uses the default. I get the following error:
TypeError: Cannot read property 'borderRadius' of undefined
styles
node_modules/@material-ui/core/Button/Button.js:41
38 | minWidth: 64,
39 | minHeight: 36,
40 | padding: '8px 16px',
> 41 | borderRadius: theme.shape.borderRadius,
42 | color: theme.palette.text.primary,
43 | transition: theme.transitions.create(['background-color', 'box-shadow', 'border'], {
44 | duration: theme.transitions.duration.short
thanks!!
Share Improve this question asked Sep 26, 2018 at 0:43 NumnumberryNumnumberry 3951 gold badge4 silver badges17 bronze badges 3-
What does your Button ponent look like? And should this line be
import { MuiThemeProvider, createMuiTheme } from '@material-ui/core/styles';
? – Patrick Dillon Commented Sep 26, 2018 at 1:35 - @PatrickDillon YOU ARE CORRECT!!! I got that import from another example. I guess it is outdated or something. Thanks for the response. – Numnumberry Commented Sep 26, 2018 at 4:14
- @PatrickDillon.. You're my SAVIOR ..spent 3 hours to fix this...BOTTOMS UP.. – muhnizar Commented Oct 14, 2018 at 11:24
3 Answers
Reset to default 5As mentioned in an earlier ment, the import statement was incorrect. This:
import { MuiThemeProvider, createMuiTheme } from 'material-ui/styles';
Should be this:
import { MuiThemeProvider, createMuiTheme } from '@material-ui/core/styles';
In case anybody else has a similar issue. The above answer never fixed my problem but pointed me in the correct direction I had to add
shape: {
borderRadius: 16
}
To my material ui theme.
So this is a two step thing for you, I'm not across Material-ui, but the main issue is that the theme-shape isn't being provided to your button ponent.
The first thing i'd do is debug and log out the buttonTheme
constant to confirm that it is matching the theme defined in https://material-ui./customization/default-theme/ with the addition of your overrides.
If you can see the the shape: border-radius: 4
portion then you know it is an issue with MuiProvider, but from looking at your code it seems to be correct.
Let me know what the theme looks like (Update your question) and we can work from there
版权声明:本文标题:javascript - When Using MUI Button: TypeError: Cannot read property 'borderRadius' of undefined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742381387a2464163.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论