Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 与MUI'反应;s useStyles()给我一个违反规则的钩子_Reactjs_Material Ui - Fatal编程技术网

Reactjs 与MUI'反应;s useStyles()给我一个违反规则的钩子

Reactjs 与MUI'反应;s useStyles()给我一个违反规则的钩子,reactjs,material-ui,Reactjs,Material Ui,我得到了可怕的“无效钩子调用”错误,我没有运行任何钩子 使用CRA安装React 已安装梅 构建简单样式页面: 将样式添加到组件: 请确保所有依赖项(包括@material ui/core)都已正确安装 这是一个工作模式。您确定文件styles.js具有useStyles吗?我检查了你的代码,效果很好。你能用这个重新创建问题吗?您的代码运行良好,就像我测试@CevaComic时提到的一样。useStyles是一个自定义挂钩。请演示如何使用SimpleComponent@Hangindev我在代码

我得到了可怕的“无效钩子调用”错误,我没有运行任何钩子

  • 使用CRA安装React
  • 已安装梅
  • 构建简单样式页面:
  • 将样式添加到组件:

  • 请确保所有依赖项(包括@material ui/core)都已正确安装


    这是一个工作模式。

    您确定文件styles.js具有useStyles吗?我检查了你的代码,效果很好。你能用这个重新创建问题吗?您的代码运行良好,就像我测试@CevaComic时提到的一样。
    useStyles
    是一个自定义挂钩。请演示如何使用
    SimpleComponent
    @Hangindev我在代码沙盒中重建了文件,它工作正常。但是,package.json中列出的一些东西是不同的……工作起来很有魅力!谢谢
    import { makeStyles } from '@material-ui/core/styles';
    
    const useStyles = makeStyles((theme) => ({
      root: {
        display: 'flex',
        justifyContent: 'center',
      },
      layout: {
        minHeight: '230px',
      },
    }));
    
    export default useStyles;
    
    import React from 'react';
    import useStyles from './styles';
    import Grid from '@material-ui/core/Grid';
    import Container from '@material-ui/core/Container';
    
    const SimpleComponent = (props) => {
      const classes = useStyles();
      return (
        <React.Fragment>
          <Container className={classes.root}>
            <Grid container spacing={3}>
              <Grid item xs={12}>
                <div>Page Content</div>;
              </Grid>
            </Grid>
          </Container>
        </React.Fragment>
      );
    };
    
    export default SimpleComponent;
    
    Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
    1. You might have mismatching versions of React and the renderer (such as React DOM)
    2. You might be breaking the Rules of Hooks
    3. You might have more than one copy of React in the same app
    See[https://reactjs.org/warnings/invalid-hook-call-warning.html][1] for tips about how to debug and fix this problem.
    
    SimpleComponent
    src/Components/PaymentHistory/PaymentHistory.js:7
       4 | import Container from '@material-ui/core/Container';
       5 | 
       6 | const SimpleComponent = (props) => {
    >  7 |   const classes = useStyles();
       8 |   return (
       9 |     <React.Fragment>
      10 |       <Container className={classes.root}>
    View compiled