第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

未捕獲的不變違規(guī):無效的掛鉤調(diào)用。React 類實現(xiàn)中的問題

未捕獲的不變違規(guī):無效的掛鉤調(diào)用。React 類實現(xiàn)中的問題

湖上湖 2021-07-01 14:15:09
我正在為 Material UI 選項卡實現(xiàn)一個 React 類。我基本上從 material ui 網(wǎng)站中獲取了選項卡的示例,并將其轉(zhuǎn)換為類兼容格式。他們網(wǎng)站上的例子如下:import React from 'react';import PropTypes from 'prop-types';import { makeStyles } from '@material-ui/core/styles';import AppBar from '@material-ui/core/AppBar';import Tabs from '@material-ui/core/Tabs';import Tab from '@material-ui/core/Tab';import Typography from '@material-ui/core/Typography';function TabContainer(props) {  return (    <Typography component="div" style={{ padding: 8 * 3 }}>      {props.children}    </Typography>  );}TabContainer.propTypes = {  children: PropTypes.node.isRequired,};const useStyles = makeStyles(theme => ({  root: {    flexGrow: 1,    backgroundColor: theme.palette.background.paper,  },}));export default function SimpleTabs() {  const classes = useStyles();  const [value, setValue] = React.useState(0);  function handleChange(event, newValue) {    setValue(newValue);  }  return (    <div className={classes.root}>      <AppBar position="static">        <Tabs value={value} onChange={handleChange}>          <Tab label="Item One" />          <Tab label="Item Two" />          <Tab label="Item Three" />        </Tabs>      </AppBar>      {value === 0 && <TabContainer>Item One</TabContainer>}      {value === 1 && <TabContainer>Item Two</TabContainer>}      {value === 2 && <TabContainer>Item Three</TabContainer>}    </div>  );}
查看完整描述

2 回答

?
智慧大石

TA貢獻1946條經(jīng)驗 獲得超3個贊

發(fā)生錯誤是因為useStyles()它makeStyles是 areact-hook并且您不能react-hooks在類組件中使用。正如您在示例中看到的,它使用了功能組件。


render() {

    const classes = useStyles(); // here is a react-hook that can't be used in class components

    return (


查看完整回答
反對 回復(fù) 2021-07-08
?
元芳怎么了

TA貢獻1798條經(jīng)驗 獲得超7個贊

如您提供的例外中所述:

Hooks 只能在函數(shù)組件內(nèi)部調(diào)用

當(dāng)然,這意味著不支持在類組件中使用鉤子。


查看完整回答
反對 回復(fù) 2021-07-08
  • 2 回答
  • 0 關(guān)注
  • 190 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號