javascript - React 无法识别 DOM 元素上的 `justifyContent` 属性

标签 javascript reactjs material-ui

const useStyles = makeStyles((theme) => ({
root:{
    padding: 0,
    textAlign: 'left',
    flexDirection: '100vh',
},
}));
    

return (
    <Container>
    <div className={classes.root}>
    <Grid container spacing={2} className={classes.Grid} justifyContent="center">
        <Grid item xs={12}>
            <RadioGroup row  aria-label="type" name="name"  className={classes.weightradio} defaultValue={"1"} value={weightRadio} onChange={handleWeightRadio}> 
                <FormControlLabel value="1"  control={<Radio />} label="1kg" />
                <FormControlLabel value="2"  control={<Radio />} label="2kg" />
                <FormControlLabel value="others"  control={<Radio />} label=">3kg" />
            </RadioGroup>
        </Grid>
        .....
   </Gid>

日志告诉我---

index.js:1 Warning: React does not recognize the justifyContent prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase justifycontent instead. If you accidentally passed it from a parent component, remove it from the DOM element.

我查了MUI 4.0的文档,支持justifyContent,问题出在哪里。

最佳答案

好的,我得到答案了。

justify 而不是 justifyContent ,并且不应该设置为 Grid root ,正确的代码如下,

        <Grid container spacing={2} className={classes.Grid}>
        <Grid item xs={12} container justify="center">   //changed here 
            <RadioGroup row  aria-label="type" name="name"  className={classes.weightradio} defaultValue={"1"} value={weightRadio} onChange={handleWeightRadio}> 
                <FormControlLabel value="1"  control={<Radio />} label="1kg" />
                <FormControlLabel value="2"  control={<Radio />} label="2kg" />
                <FormControlLabel value="others"  control={<Radio />} label=">3kg" />
            </RadioGroup>
        </Grid>

关于javascript - React 无法识别 DOM 元素上的 `justifyContent` 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69862839/

相关文章:

reactjs - Material -UI React : Global theme override for Paper component

css - AppBar 与其他元素重叠

javascript - 根据滚动更改我的 div 容器的位置

javascript - 如果 D3.js 树形图的子级具有相同的值,则连接它们

javascript - React-router v4,URL 更改但组件不呈现

css - 如何在 'Ant Design' 中分隔菜单和菜单选项卡内容宽度?

javascript - 如何使用不同页面上的复选框更新进度条

javascript - Leaflet/Progressive Web App - 在图 block 404 上快速周转(也许使用 Workbox)?

html - 在不使用 100vh 的情况下强制 div 为整页高度

reactjs - 在 Material-UI 面包屑导航中使用 React Router DOM 路由