首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >对于React应用程序主题,是否存在material-ui makeStyles与SCSS架构的优势?

对于React应用程序主题,是否存在material-ui makeStyles与SCSS架构的优势?
EN

Stack Overflow用户
提问于 2020-01-12 01:01:01
回答 2查看 1.6K关注 0票数 2

我刚刚加入了一个开发React应用程序的团队。我们目前依赖于材料UI,包括makeStyles,来设计应用程序。我的任务之一就是弄清楚我们的全球主题。在我的传统中,我一直依赖于LESS和SCSS来实现应用程序样式和主题架构。

与切换主题架构使用makeStyles相比,坚持使用Material use (除了它已经实现的事实之外)有优势吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-10-22 14:53:49

makeStyles是使用基于主题的UI的好方法。它允许你使用常见的属性和方法来生成基于样式的配置变量。

主题的钩子用法:

代码语言:javascript
复制
const useStyles = makeStyles((theme:MyCustomTheme)=>{
  root: {
    background: 'linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)',
    border: theme.myBorder,
    borderRadius: 3,
    boxShadow: theme.shaodws.boxShadowPrimary,
    color: theme.colors.primary,
    height: theme.size(1),
    padding: '0 30px',
  },
});

export default function MyCustomThemeButton() {
  const classes = useStyles();
  return <Button className={classes.root}>Hook</Button>;
}

此外,您还可以在实现钩子时提供自定义道具:

代码语言:javascript
复制
const useStyles = makeStyles((theme:MyCustomTheme)=>{
  root: (props) => ({
    border: props.hasBorder ? theme.myBorder : 'none',
    color: props.textColor || theme.color.text.pirmary
  })
});

export default function MyCustomThemeButton(props) {
  const [active, setActive] = useState(false);
  const classes = useStyles({
    hasBorder: props.isOutsideBox,
    textColor: active ? "red" : "yellow"
  });
  return <Button className={classes.root}>Hook</Button>;
}

要阅读有关该主题的更多信息,请访问Material UI styles

票数 1
EN

Stack Overflow用户

发布于 2020-10-22 09:06:04

我可以很好地交替使用makeStyles和scss。

但是,我会避免在组件级别混合它们……这可能会让人感到困惑。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59696613

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档