admin管理员组文章数量:1394601
I pass props to a button ponent:
const StoreButton = ({ storeColor }) => {
const borderBottom = `solid 3px ${storeColor}`;
const classes = useStyles({ borderBottom });
return (
<Button variant="outlined" size="small" className={classes.button}>
Store
</ Button>
)
};
I create the borderBottom
property before I use it in classes. I would like to construct the property inside makeStyles but this leads to an error:
const useStyles = makeStyles(theme => ({
button: {
borderBottom: props => props.borderBottom,
// borderBottom: `solid 3px ${props => props.borderBottom}`; // function is pasted in
},
}));
If I construct the CSS shorthand inside makeStyles it creates solid 3px solid 3px function(props){return props.borderBottom;}
. when I inspect it in Chrome. Thus, this way the styles are invalid.
Is there a way to pass props to CSS shorthand properties without this workaround of creating it outside makeStyles?
I pass props to a button ponent:
const StoreButton = ({ storeColor }) => {
const borderBottom = `solid 3px ${storeColor}`;
const classes = useStyles({ borderBottom });
return (
<Button variant="outlined" size="small" className={classes.button}>
Store
</ Button>
)
};
I create the borderBottom
property before I use it in classes. I would like to construct the property inside makeStyles but this leads to an error:
const useStyles = makeStyles(theme => ({
button: {
borderBottom: props => props.borderBottom,
// borderBottom: `solid 3px ${props => props.borderBottom}`; // function is pasted in
},
}));
If I construct the CSS shorthand inside makeStyles it creates solid 3px solid 3px function(props){return props.borderBottom;}
. when I inspect it in Chrome. Thus, this way the styles are invalid.
Is there a way to pass props to CSS shorthand properties without this workaround of creating it outside makeStyles?
Share Improve this question asked Sep 8, 2019 at 12:46 EliteRaceElephantEliteRaceElephant 8,1624 gold badges56 silver badges66 bronze badges1 Answer
Reset to default 8You almost had it right, the only thing to change is this:
borderBottom: props => `1px solid ${props.color}`,
Now the value is a proper function. Inside the function it constructs the correct string value.
本文标签: javascriptPass props to makeStyles and use in CSS shorthand property in Material UIStack Overflow
版权声明:本文标题:javascript - Pass props to makeStyles and use in CSS shorthand property in Material UI - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744095711a2590245.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论