React material-ui无法读取null的属性“ direction”

海克·萨法良(Hayk Safaryan)

出现此错误。

Cannot read property 'direction' of null

127 | var options = (0, _extends2.default)({}, stylesCreator.options, stylesOptions, {
> 128 |   flip: typeof stylesOptions.flip === 'boolean' ? stylesOptions.flip : theme.direction === 'rtl'
      | ^  129 | });
  130 | var sheetsRegistry = stylesOptions.sheetsRegistry;

发生这种情况是由于以下代码。 useStyles

// @flow
import * as React from 'react';
import Avatar from '@material-ui/core/Avatar';
import Button from '@material-ui/core/Button';
import FormControl from '@material-ui/core/FormControl';
import FormControlLabel from '@material-ui/core/FormControlLabel';
import Checkbox from '@material-ui/core/Checkbox';
import Input from '@material-ui/core/Input';
import InputLabel from '@material-ui/core/InputLabel';
import LockIcon from '@material-ui/icons/LockOutlined';
import Paper from '@material-ui/core/Paper';
import Typography from '@material-ui/core/Typography';
import { makeStyles } from '@material-ui/styles';

const useStyles = makeStyles(theme => ({
  main: {
    width: 'auto',
    display: 'block', // Fix IE 11 issue.
    marginLeft: theme.spacing.unit * 3,
    marginRight: theme.spacing.unit * 3,
    [theme.breakpoints.up(400 + theme.spacing.unit * 3 * 2)]: {
      width: 400,
      marginLeft: 'auto',
      marginRight: 'auto',
    },
  },
  paper: {
    marginTop: theme.spacing.unit * 8,
    display: 'flex',
    flexDirection: 'column',
    alignItems: 'center',
    padding: `${theme.spacing.unit * 2}px\
    ${theme.spacing.unit * 3}px\
    ${theme.spacing.unit * 3}px`,
  },
  avatar: {
    margin: theme.spacing.unit,
    backgroundColor: theme.palette.secondary.main,
  },
  form: {
    width: '100%', // Fix IE 11 issue.
    marginTop: theme.spacing.unit,
  },
  submit: {
    marginTop: theme.spacing.unit * 3,
  },
}));

const Login = (props) => {
  const classes = useStyles();

  return (
    <main className={classes.main}>
      <Paper className={classes.paper}>
        <Avatar className={classes.avatar}>
          <LockIcon />
        </Avatar>
        <Typography component="h1" variant="h5">
          Sign in
        </Typography>
        <form className={classes.form}>
          <FormControl margin="normal" required fullWidth>
            <InputLabel htmlFor="email">Email Address</InputLabel>
            <Input id="email" name="email" autoComplete="email" autoFocus />
          </FormControl>
          <FormControl margin="normal" required fullWidth>
            <InputLabel htmlFor="password">Password</InputLabel>
            <Input
              name="password"
              type="password"
              id="password"
              autoComplete="current-password"
            />
          </FormControl>
          <FormControlLabel
            control={<Checkbox value="remember" color="primary" />}
            label="Remember me"
          />
          <Button
            type="submit"
            fullWidth
            variant="contained"
            color="primary"
            className={classes.submit}
          >
            Sign in
          </Button>
        </form>
      </Paper>
    </main>
  );
};

export default Login;

这是我的应用程序组件

import React from 'react';
import { MuiThemeProvider } from '@material-ui/core/styles';
import CssBaseline from '@material-ui/core/CssBaseline';
import {
  Switch,
} from 'react-router-dom';
import theme from './theme';
import Auth from './Auth';

const App = () => (
  <MuiThemeProvider theme={theme}>
    <CssBaseline />
    <Switch>
      <Auth />
    </Switch>
  </MuiThemeProvider>
);

export default App;

theme似乎是不确定的里面makeStyles你知道这里发生了什么吗?

海克·萨法良(Hayk Safaryan)

App.js

一个应该使用

import {ThemeProvider} from '@material-ui/styles';

而不是旧的:

import { MuiThemeProvider } from '@material-ui/core/styles';

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

React Material-ui Autocomplete:清除搜索字段时获取“TypeError:无法读取null的属性'id'”

React Material-UI Modal TypeError:无法读取未定义的属性“ hasOwnProperty”

无法获取Material-UI的目标属性-选择React组件

如何在 Material UI 中使用 Grid direction="row"

React 无法读取 null 的属性

Bootstrap与Material UI for React?

React Material UI网格

React Material UI onFocusOut

React Material UI 滑块

Material-UI:无法在Grid direction = column alignItems =“ center”内调整Grid项目的大小

无法正确渲染Material UI React Grid

WithStyles无法在Material UI中用于React

React Material UI Select 无法正常工作

React和Material Ui入门

React-Material UI与Reactstrap

React Material UI 多重折叠

React refs:无法读取null的属性“ focus”

TypeError:无法读取null的属性'substr'-React

无法读取null React的属性'style'

无法在React中读取null的属性'style'

无法读取 Material UI 类

如何为 Material UI 滑块编写单元测试?尝试呈现组件时抛出“错误:无法读取 null 的属性‘addEventListener’”

我可以在Angular Material Menu组件上使用哪些不同的Direction属性?

类型错误:无法读取 null 的属性(读取“classList”)React

React - 无法读取 null 的属性(“正在读取 useState”)错误

React Responsive Carousel - 无法读取 null 的属性(读取“类型”)

React Material UI 列宽属性不展开

在Material-UI中使用React的'ref'属性

React - Material UI | 找不到模块:无法解析“material-ui/Button”