首页 > 解决方案 > 使用 Material UI 中的 theme.breakpoints.down('') 时出错

问题描述

我是初学者,我在前端使用材料 UI,我试图根据材料 UI 中的文档使用 theme.breakpoints.down 使我的应用程序响应,但它返回错误:

主题.断点.down()

这就是我的代码:

const useStyle = makeStyles({
root : {
    height:"100vh",
    display:"flex",
    justifyContent:"space-evenly",
    alignItems:"center",
    [theme.breakpoints.down('sm')]:{
        flexDirection:"column"
    }
}

})

我想了解发生了什么,如果可能的话,可以做些什么来解决它。谢谢你。

标签: javascriptreactjsmaterial-ui

解决方案


makeStyles 是一个函数并返回钩子,因此您可以将“主题”作为参数传递

所以应该是这样的:

const useStyle = makeStyles((theme)=>({
root : {
    height:"100vh",
    display:"flex",
    justifyContent:"space-evenly",
    alignItems:"center",
    [theme.breakpoints.down('sm')]:{
        flexDirection:"column"
    }
}}))


推荐阅读