Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/448.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.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
Javascript 与物料界面反应_Javascript_Reactjs_Components_Material Ui_React Hooks - Fatal编程技术网

Javascript 与物料界面反应

Javascript 与物料界面反应,javascript,reactjs,components,material-ui,react-hooks,Javascript,Reactjs,Components,Material Ui,React Hooks,我试图使用material ui中的代码,但出现以下错误: 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

我试图使用material ui中的代码,但出现以下错误:

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
如果我没有使用类,我不确定是什么导致了这个问题(因为我知道react钩子不能在类内部使用)。我想知道这是否与ReactDOM有关

这是我正在使用的唯一代码:

=======index.js=======

import React from 'react';
import ReactDOM from 'react-dom';
import App from './Pages/HomePage.jsx';

ReactDOM.render(<App />, document.getElementById('root'));
import React, { useState } from 'react';
import AB from '../Components/AppBar';

export default function HP() {
  const [buttonClicked, setButtonClicked] = useState(false);

  if (buttonClicked === false ) 
      return (
          <Button color="info" onClick={() => setButtonClicked(true)}>Get Started</Button>
      )
  if (buttonClicked) return (<AB/>)
};
import React from 'react';
import AppBar from '@material-ui/core/AppBar';
import Toolbar from '@material-ui/core/Toolbar';
import IconButton from '@material-ui/core/IconButton';
import Typography from '@material-ui/core/Typography';
import InputBase from '@material-ui/core/InputBase';
import { fade, makeStyles } from '@material-ui/core/styles';
import MenuIcon from '@material-ui/icons/Menu';
import SearchIcon from '@material-ui/icons/Search';

const useStyles = makeStyles(theme => ({
  root: {
    flexGrow: 1,
  },
  menuButton: {
    marginRight: theme.spacing(2),
  },
  title: {
    flexGrow: 1,
    display: 'none',
    [theme.breakpoints.up('sm')]: {
      display: 'block',
    },
  },
  search: {
    position: 'relative',
    borderRadius: theme.shape.borderRadius,
    backgroundColor: fade(theme.palette.common.white, 0.15),
    '&:hover': {
      backgroundColor: fade(theme.palette.common.white, 0.25),
    },
    marginLeft: 0,
    width: '100%',
    [theme.breakpoints.up('sm')]: {
      marginLeft: theme.spacing(1),
      width: 'auto',
    },
  },
  searchIcon: {
    width: theme.spacing(7),
    height: '100%',
    position: 'absolute',
    pointerEvents: 'none',
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'center',
  },
  inputRoot: {
    color: 'inherit',
  },
  inputInput: {
    padding: theme.spacing(1, 1, 1, 7),
    transition: theme.transitions.create('width'),
    width: '100%',
    [theme.breakpoints.up('sm')]: {
      width: 120,
      '&:focus': {
        width: 200,
      },
    },
  },
}));

export default function SearchAppBar() {
  const classes = useStyles();

  return (
    <div className={classes.root}>
      <AppBar position="static">
        <Toolbar>
          <IconButton
            edge="start"
            className={classes.menuButton}
            color="inherit"
            aria-label="open drawer"
          >
            <MenuIcon />
          </IconButton>
          <Typography className={classes.title} variant="h6" noWrap>
            Material-UI
          </Typography>
          <div className={classes.search}>
            <div className={classes.searchIcon}>
              <SearchIcon />
            </div>
            <InputBase
              placeholder="Search…"
              classes={{
                root: classes.inputRoot,
                input: classes.inputInput,
              }}
              inputProps={{ 'aria-label': 'search' }}
            />
          </div>
        </Toolbar>
      </AppBar>
    </div>
  );
}
从“React”导入React;
从“react dom”导入react dom;
从“/Pages/HomePage.jsx”导入应用程序;
ReactDOM.render(,document.getElementById('root'));
=======HomePage.js=======

import React from 'react';
import ReactDOM from 'react-dom';
import App from './Pages/HomePage.jsx';

ReactDOM.render(<App />, document.getElementById('root'));
import React, { useState } from 'react';
import AB from '../Components/AppBar';

export default function HP() {
  const [buttonClicked, setButtonClicked] = useState(false);

  if (buttonClicked === false ) 
      return (
          <Button color="info" onClick={() => setButtonClicked(true)}>Get Started</Button>
      )
  if (buttonClicked) return (<AB/>)
};
import React from 'react';
import AppBar from '@material-ui/core/AppBar';
import Toolbar from '@material-ui/core/Toolbar';
import IconButton from '@material-ui/core/IconButton';
import Typography from '@material-ui/core/Typography';
import InputBase from '@material-ui/core/InputBase';
import { fade, makeStyles } from '@material-ui/core/styles';
import MenuIcon from '@material-ui/icons/Menu';
import SearchIcon from '@material-ui/icons/Search';

const useStyles = makeStyles(theme => ({
  root: {
    flexGrow: 1,
  },
  menuButton: {
    marginRight: theme.spacing(2),
  },
  title: {
    flexGrow: 1,
    display: 'none',
    [theme.breakpoints.up('sm')]: {
      display: 'block',
    },
  },
  search: {
    position: 'relative',
    borderRadius: theme.shape.borderRadius,
    backgroundColor: fade(theme.palette.common.white, 0.15),
    '&:hover': {
      backgroundColor: fade(theme.palette.common.white, 0.25),
    },
    marginLeft: 0,
    width: '100%',
    [theme.breakpoints.up('sm')]: {
      marginLeft: theme.spacing(1),
      width: 'auto',
    },
  },
  searchIcon: {
    width: theme.spacing(7),
    height: '100%',
    position: 'absolute',
    pointerEvents: 'none',
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'center',
  },
  inputRoot: {
    color: 'inherit',
  },
  inputInput: {
    padding: theme.spacing(1, 1, 1, 7),
    transition: theme.transitions.create('width'),
    width: '100%',
    [theme.breakpoints.up('sm')]: {
      width: 120,
      '&:focus': {
        width: 200,
      },
    },
  },
}));

export default function SearchAppBar() {
  const classes = useStyles();

  return (
    <div className={classes.root}>
      <AppBar position="static">
        <Toolbar>
          <IconButton
            edge="start"
            className={classes.menuButton}
            color="inherit"
            aria-label="open drawer"
          >
            <MenuIcon />
          </IconButton>
          <Typography className={classes.title} variant="h6" noWrap>
            Material-UI
          </Typography>
          <div className={classes.search}>
            <div className={classes.searchIcon}>
              <SearchIcon />
            </div>
            <InputBase
              placeholder="Search…"
              classes={{
                root: classes.inputRoot,
                input: classes.inputInput,
              }}
              inputProps={{ 'aria-label': 'search' }}
            />
          </div>
        </Toolbar>
      </AppBar>
    </div>
  );
}
import React,{useState}来自“React”;
从“../Components/AppBar”导入AB;
导出默认函数HP(){
const[buttonClicked,setButtonClicked]=useState(false);
如果(按钮点击===错误)
返回(
setButtonClicked(true)}>开始
)
如果(按钮勾选)返回()
};
=======AppBar.js=======

import React from 'react';
import ReactDOM from 'react-dom';
import App from './Pages/HomePage.jsx';

ReactDOM.render(<App />, document.getElementById('root'));
import React, { useState } from 'react';
import AB from '../Components/AppBar';

export default function HP() {
  const [buttonClicked, setButtonClicked] = useState(false);

  if (buttonClicked === false ) 
      return (
          <Button color="info" onClick={() => setButtonClicked(true)}>Get Started</Button>
      )
  if (buttonClicked) return (<AB/>)
};
import React from 'react';
import AppBar from '@material-ui/core/AppBar';
import Toolbar from '@material-ui/core/Toolbar';
import IconButton from '@material-ui/core/IconButton';
import Typography from '@material-ui/core/Typography';
import InputBase from '@material-ui/core/InputBase';
import { fade, makeStyles } from '@material-ui/core/styles';
import MenuIcon from '@material-ui/icons/Menu';
import SearchIcon from '@material-ui/icons/Search';

const useStyles = makeStyles(theme => ({
  root: {
    flexGrow: 1,
  },
  menuButton: {
    marginRight: theme.spacing(2),
  },
  title: {
    flexGrow: 1,
    display: 'none',
    [theme.breakpoints.up('sm')]: {
      display: 'block',
    },
  },
  search: {
    position: 'relative',
    borderRadius: theme.shape.borderRadius,
    backgroundColor: fade(theme.palette.common.white, 0.15),
    '&:hover': {
      backgroundColor: fade(theme.palette.common.white, 0.25),
    },
    marginLeft: 0,
    width: '100%',
    [theme.breakpoints.up('sm')]: {
      marginLeft: theme.spacing(1),
      width: 'auto',
    },
  },
  searchIcon: {
    width: theme.spacing(7),
    height: '100%',
    position: 'absolute',
    pointerEvents: 'none',
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'center',
  },
  inputRoot: {
    color: 'inherit',
  },
  inputInput: {
    padding: theme.spacing(1, 1, 1, 7),
    transition: theme.transitions.create('width'),
    width: '100%',
    [theme.breakpoints.up('sm')]: {
      width: 120,
      '&:focus': {
        width: 200,
      },
    },
  },
}));

export default function SearchAppBar() {
  const classes = useStyles();

  return (
    <div className={classes.root}>
      <AppBar position="static">
        <Toolbar>
          <IconButton
            edge="start"
            className={classes.menuButton}
            color="inherit"
            aria-label="open drawer"
          >
            <MenuIcon />
          </IconButton>
          <Typography className={classes.title} variant="h6" noWrap>
            Material-UI
          </Typography>
          <div className={classes.search}>
            <div className={classes.searchIcon}>
              <SearchIcon />
            </div>
            <InputBase
              placeholder="Search…"
              classes={{
                root: classes.inputRoot,
                input: classes.inputInput,
              }}
              inputProps={{ 'aria-label': 'search' }}
            />
          </div>
        </Toolbar>
      </AppBar>
    </div>
  );
}
从“React”导入React;
从“@material ui/core/AppBar”导入AppBar;
从“@material ui/core/Toolbar”导入工具栏;
从“@material ui/core/IconButton”导入IconButton;
从“@material ui/core/Typography”导入排版;
从“@material ui/core/InputBase”导入InputBase;
从“@material ui/core/styles”导入{fade,makeStyles};
从“@material ui/icons/Menu”导入菜单图标;
从“@material ui/icons/Search”导入SearchIcon;
const useStyles=makeStyles(主题=>({
根目录:{
flexGrow:1,
},
菜单按钮:{
边缘光:主题。间距(2),
},
标题:{
flexGrow:1,
显示:“无”,
[theme.breakpoints.up('sm'):{
显示:“块”,
},
},
搜索:{
位置:'相对',
borderRadius:theme.shape.borderRadius,
背景色:淡入淡出(theme.palette.common.white,0.15),
“&:悬停”:{
背景色:淡入淡出(theme.palette.common.white,0.25),
},
marginLeft:0,
宽度:“100%”,
[theme.breakpoints.up('sm'):{
边缘左侧:主题。间距(1),
宽度:“自动”,
},
},
搜索图标:{
宽度:主题。间距(7),
高度:“100%”,
位置:'绝对',
pointerEvents:'无',
显示:“flex”,
对齐项目:“居中”,
为内容辩护:“中心”,
},
输入根:{
颜色:“继承”,
},
输入输出:{
填充:主题。间距(1,1,1,7),
transition:theme.transitions.create('width'),
宽度:“100%”,
[theme.breakpoints.up('sm'):{
宽度:120,
“&:焦点”:{
宽度:200,
},
},
},
}));
导出默认函数SearchAppBar(){
const classes=useStyles();
返回(
材料界面
);
}

使用样式或制作样式本身是材质ui提供的挂钩,它应该位于功能组件内部

import React from 'react'
import AppBar from '@material-ui/core/AppBar'
import Toolbar from '@material-ui/core/Toolbar'
import IconButton from '@material-ui/core/IconButton'
import Typography from '@material-ui/core/Typography'
import InputBase from '@material-ui/core/InputBase'
import { fade, makeStyles } from '@material-ui/core/styles'
import MenuIcon from '@material-ui/icons/Menu'
import SearchIcon from '@material-ui/icons/Search'

export default function SearchAppBar() {
    const classes = useStyles()

    return (
        <div className={classes.root}>
            <AppBar position="static">
                <Toolbar>
                    <IconButton
                        edge="start"
                        className={classes.menuButton}
                        color="inherit"
                        aria-label="open drawer">
                        <MenuIcon />
                    </IconButton>
                    <Typography className={classes.title} variant="h6" noWrap>
                        Material-UI
                    </Typography>
                    <div className={classes.search}>
                        <div className={classes.searchIcon}>
                            <SearchIcon />
                        </div>
                        <InputBase
                            placeholder="Search…"
                            classes={{
                                root: classes.inputRoot,
                                input: classes.inputInput
                            }}
                            inputProps={{ 'aria-label': 'search' }}
                        />
                    </div>
                </Toolbar>
            </AppBar>
        </div>
    )
}

const useStyles = makeStyles(theme => ({
    root: {
        flexGrow: 1
    },
    menuButton: {
        marginRight: theme.spacing(2)
    },
    title: {
        flexGrow: 1,
        display: 'none',
        [theme.breakpoints.up('sm')]: {
            display: 'block'
        }
    },
    search: {
        position: 'relative',
        borderRadius: theme.shape.borderRadius,
        backgroundColor: fade(theme.palette.common.white, 0.15),
        '&:hover': {
            backgroundColor: fade(theme.palette.common.white, 0.25)
        },
        marginLeft: 0,
        width: '100%',
        [theme.breakpoints.up('sm')]: {
            marginLeft: theme.spacing(1),
            width: 'auto'
        }
    },
    searchIcon: {
        width: theme.spacing(7),
        height: '100%',
        position: 'absolute',
        pointerEvents: 'none',
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'center'
    },
    inputRoot: {
        color: 'inherit'
    },
    inputInput: {
        padding: theme.spacing(1, 1, 1, 7),
        transition: theme.transitions.create('width'),
        width: '100%',
        [theme.breakpoints.up('sm')]: {
            width: 120,
            '&:focus': {
                width: 200
            }
        }
    }
}))

从“React”导入React
从“@material ui/core/AppBar”导入AppBar
从“@material ui/core/Toolbar”导入工具栏
从“@material ui/core/IconButton”导入IconButton
从“@material ui/core/Typography”导入排版
从“@material ui/core/InputBase”导入InputBase
从“@material ui/core/styles”导入{fade,makeStyles}
从“@material ui/icons/Menu”导入菜单图标
从“@material ui/icons/Search”导入SearchIcon
导出默认函数SearchAppBar(){
常量类=useStyles()
返回(
材料界面
)
}
const useStyles=makeStyles(主题=>({
根目录:{
flexGrow:1
},
菜单按钮:{
边缘光:主题。间距(2)
},
标题:{
flexGrow:1,
显示:“无”,
[theme.breakpoints.up('sm'):{
显示:“块”
}
},
搜索:{
位置:'相对',
borderRadius:theme.shape.borderRadius,
背景色:淡入淡出(theme.palette.common.white,0.15),
“&:悬停”:{
背景色:淡入淡出(theme.palette.common.white,0.25)
},
marginLeft:0,
宽度:“100%”,
[theme.breakpoints.up('sm'):{
边缘左侧:主题。间距(1),
宽度:“自动”
}
},
搜索图标:{
宽度:主题。间距(7),
高度:“100%”,
位置:'绝对',
pointerEvents:'无',
显示:“flex”,
对齐项目:“居中”,
为内容辩护:“中心”
},
输入根:{
颜色:“继承”
},
输入输出:{
填充:主题。间距(1,1,1,7),
transition:theme.transitions.create('width'),
宽度:“100%”,
[theme.breakpoints.up('sm'):{
宽度:120,
“&:焦点”:{
宽度:200
}
}
}
}))

使用样式或制作样式本身是材质ui提供的挂钩,它应该位于功能组件内部

import React from 'react'
import AppBar from '@material-ui/core/AppBar'
import Toolbar from '@material-ui/core/Toolbar'
import IconButton from '@material-ui/core/IconButton'
import Typography from '@material-ui/core/Typography'
import InputBase from '@material-ui/core/InputBase'
import { fade, makeStyles } from '@material-ui/core/styles'
import MenuIcon from '@material-ui/icons/Menu'
import SearchIcon from '@material-ui/icons/Search'

export default function SearchAppBar() {
    const classes = useStyles()

    return (
        <div className={classes.root}>
            <AppBar position="static">
                <Toolbar>
                    <IconButton
                        edge="start"
                        className={classes.menuButton}
                        color="inherit"
                        aria-label="open drawer">
                        <MenuIcon />
                    </IconButton>
                    <Typography className={classes.title} variant="h6" noWrap>
                        Material-UI
                    </Typography>
                    <div className={classes.search}>
                        <div className={classes.searchIcon}>
                            <SearchIcon />
                        </div>
                        <InputBase
                            placeholder="Search…"
                            classes={{
                                root: classes.inputRoot,
                                input: classes.inputInput
                            }}
                            inputProps={{ 'aria-label': 'search' }}
                        />
                    </div>
                </Toolbar>
            </AppBar>
        </div>
    )
}

const useStyles = makeStyles(theme => ({
    root: {
        flexGrow: 1
    },
    menuButton: {
        marginRight: theme.spacing(2)
    },
    title: {
        flexGrow: 1,
        display: 'none',
        [theme.breakpoints.up('sm')]: {
            display: 'block'
        }
    },
    search: {
        position: 'relative',
        borderRadius: theme.shape.borderRadius,
        backgroundColor: fade(theme.palette.common.white, 0.15),
        '&:hover': {
            backgroundColor: fade(theme.palette.common.white, 0.25)
        },
        marginLeft: 0,
        width: '100%',
        [theme.breakpoints.up('sm')]: {
            marginLeft: theme.spacing(1),
            width: 'auto'
        }
    },
    searchIcon: {
        width: theme.spacing(7),
        height: '100%',
        position: 'absolute',
        pointerEvents: 'none',
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'center'
    },
    inputRoot: {
        color: 'inherit'
    },
    inputInput: {
        padding: theme.spacing(1, 1, 1, 7),
        transition: theme.transitions.create('width'),
        width: '100%',
        [theme.breakpoints.up('sm')]: {
            width: 120,
            '&:focus': {
                width: 200
            }
        }
    }
}))

从“React”导入React
从“@material ui/core/AppBar”导入AppBar
从“@material ui/core/Toolbar”导入工具栏
从“@material ui/core/IconButton”导入IconButton
从“@material ui/core/Typography”导入排版
从“@material ui/core/InputBase”导入InputBase
从“@material ui/core/styles”导入{fade,makeStyles}
从“@material ui/icons/Menu”导入菜单图标
从“@material ui/icons/Search”导入SearchIcon
导出默认函数SearchAppBar(){
常量类=useStyles()
返回(
材料界面