简体   繁体   English

如何在 React 中使用带有 MuiThemeProvider 的 material-ui 按钮作为弹出窗口的触发器

[英]How to use a material-ui button with MuiThemeProvider as Popup's trigger in React

I'm trying to use as a trigger of a Popup in React a button with custom theme:我正在尝试将具有自定义主题的按钮用作 React 中弹出窗口的触发器:

 <PopUp modal trigger={
                        <MuiThemeProvider theme={buttonTheme}>
                            <Button variant="contained" color="secondary">Excluir</Button>
                        </MuiThemeProvider>
 }>

But when I do this, I get this error: "Failed prop type: The following props are not supported: onClick . Please remove them. in ThemeProvider" and "Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?".但是当我这样做时,我收到此错误:“失败的道具类型:不支持以下道具: onClick 。请在 ThemeProvider 中删除它们”和“无法为函数组件提供参考。尝试访问此参考将失败。是否你的意思是使用 React.forwardRef()?”。 I would like to stop the error.我想停止错误。 The button gets colorful, but it doesn't open the Popup.该按钮变得丰富多彩,但它不会打开弹出窗口。

You just need to put the tag outside the trigger.您只需要将标签放在触发器之外。

<MuiThemeProvider theme={buttonTheme}>
         <PopUp modal trigger={<Button variant="contained" color="secondary">Excluir</Button>>}
</MuiThemeProvider>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM