是否可以覆盖material-ui组件的默认props? [英] Is it possible to override material-ui components default props?
本文介绍了是否可以覆盖material-ui组件的默认props?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
让我说我希望material-ui
中的每个Button
组件都具有默认的道具variant="contained" color="secondary"
,这可能吗?
Lets say i want every Button
component from material-ui
to have a default props of variant="contained" color="secondary"
is it possible ?
推荐答案
有关此文档,请参见: https://material-ui.com/customization/globals/#default-props
The documentation for this is here: https://material-ui.com/customization/globals/#default-props
以下是如何执行此操作的示例:
Here is an example of how to do this:
import React from "react";
import ReactDOM from "react-dom";
import {createMuiTheme, MuiThemeProvider, Button} from "@material-ui/core";
const theme = createMuiTheme({
props: {
MuiButton: {
variant: "contained",
color: "secondary"
}
}
});
function App() {
return (
<MuiThemeProvider theme={theme}>
<Button>Props defaulted</Button>
</MuiThemeProvider>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
这篇关于是否可以覆盖material-ui组件的默认props?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文