【问题标题】:Tab Error in React : Check the render method of TabPanelReact 中的选项卡错误:检查 TabPanel 的渲染方法
【发布时间】:2020-01-10 04:29:33
【问题描述】:

我想使用带有以下代码的材料设计选项卡:

import React, { PureComponent } from 'react'
import { Field, reduxForm,change } from 'redux-form'
import PropTypes from 'prop-types'

import { Update,Get } from '../../_actions/baseInfo/reseller'
import { connectTo } from '../../_utils/generic'
import { isValid } from '../../_utils/forms'
import textfield from '../../_components/fields/textfield/textfield'
import UpdateForm from '../../_components/updateForm/updateForm'
import styles from './Styles.module.scss'
import { getCustomerType } from '../../_actions/generic'
import { withStyles } from '@material-ui/core/styles'
import { Filter as FilterResellers } from '../../_actions/baseInfo/reseller'
import { Filter as FilterRegions } from '../../_actions/baseInfo/region'
import { Filter as FilterCities } from '../../_actions/baseInfo/city'
import { Filter as FilterAccounting } from '../../_actions/baseInfo/accounting'
import filterField from '../../_components/fields/filterField/FilterField'
import {AppBar, Tab,Tabs } from '@material-ui/core';
import {Typography} from '@material-ui/core/Typography'
import Box from '@material-ui/core/Box'
import { Paper } from '@material-ui/core';
import selectField from '../../_components/fields/selectField/selectField'
import classNames from 'classnames';
import dateField from '../../_components/fields/dateField/dateField'
import checkbox from '../../_components/fields/checkbox/checkbox'
import { Break } from '../../_components/Break';
import filefield from '../../_components/fields/filefield/filefield';
....

function TabPanel(props) {
    const { children, value, index, ...other } = props;

    return (
      <Typography
        component="div"
        role="tabpanel"
        hidden={value !== index}
        id={`simple-tabpanel-${index}`}
        aria-labelledby={`simple-tab-${index}`}
        {...other}
      >
        <Box p={3}>{children}</Box>
      </Typography>
    );
  }


  TabPanel.propTypes = {
    children: PropTypes.node,
    index: PropTypes.any.isRequired,
    value: PropTypes.any.isRequired,
  };


class UpdatePage extends PureComponent {

    constructor(props) {
        super(props)

        this.state = {
          value:0,
        }
    }

    handleChange(event, newValue){
          this.setState({value:newValue})
    }

    a11yProps(index) {
        return {
          id: `simple-tab-${index}`,
          'aria-controls': `simple-tabpanel-${index}`,
        };
    }

    componentDidMount() {
        const { Get,match:{params:{resellerId}} } = this.props
        Get({resellerId})

    }

    render() {

        const { handleSubmit, enabledSubmit,match:{params:{resellerId}} } = this.props
        const fields = [
            <div>
                <AppBar position="static">
                    <Tabs onChange={this.handleChange} value={this.state.value} aria-label="simple tabs example">
                        <Tab label="One" {...this.a11yProps(0)} />
                        <Tab label="Two" {...this.a11yProps(1)} />
                        <Tab label="Three"  {...this.a11yProps(2)} />
                    </Tabs>
                </AppBar>
                <TabPanel value={this.state.value} index={0}>
                    <label>1</label>
                </TabPanel>
                <TabPanel value={this.state.value} index={1}>
                    <label>2</label>
                </TabPanel>
                <TabPanel value={this.state.value} index={2}>
                    <label>3</label>
                </TabPanel>
            </div>

        ]
....

但出现以下错误:

元素类型无效:应为字符串(用于内置组件) 或类/函数(用于复合组件)但得到:未定义。你 可能忘记从定义它的文件中导出您的组件, 或者您可能混淆了默认导入和命名导入。

检查 TabPanel 的渲染方法。

【问题讨论】:

  • 看起来您错过了导入或导入错误。可以粘贴其余代码吗?
  • @paruchuri-p 我添加导入部分
  • 谢谢,让我检查一下。
  • 添加了一个解决方案,让我知道它是否有效。干杯!

标签: reactjs material-design material-ui


【解决方案1】:

render return 语句在哪里?添加返回字段;

render() {

        const { handleSubmit, enabledSubmit,match:{params:{resellerId}} } = this.props
        const fields = [
            ...
        ];

        return fields;
}

【讨论】:

  • 当我添加标签出现问题时,它已经返回并正常工作
【解决方案2】:

这是问题:

import Typography from '@material-ui/core/Typography';

您将其作为命名导入 {Typography} 导入

将其作为命名导入:

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

【讨论】:

  • 问题依然存在
  • 是的一样。我用你提到的第一个
  • 那么您肯定错过了其他一些导入。所以也要检查其他人。
  • 我根据 Material Design 的帮助添加它:material-ui.com/components/tabs
猜你喜欢
  • 2013-06-28
  • 2021-08-17
  • 2021-08-03
  • 2019-03-21
  • 2020-05-31
  • 1970-01-01
  • 1970-01-01
  • 2020-05-19
  • 1970-01-01
相关资源
最近更新 更多