react-swipeable-views 在使用时显示错误
react-swipable-views shows error when used
我正在尝试在我的 React 应用程序中使用 react-swipable-views
。我收到以下错误:-
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
我是这样导入的:
import SwipeableViews from "react-swipeable-views";
用法:
import React, { Component } from 'react';
import './../index.css';
import {
Tabs,
Tab,
Grid,
Paper,
Typography,
Box,
Icon
} from '@material-ui/core';
import PropTypes from 'prop-types';
import A from './components/A/A';
import B from './components/B/B';
import C from './components/C/C';
import D from './components/D/D';
import E from './components/E/E';
import SwipeableViews from "react-swipeable-views";
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}
>
{value === index && <Box p={3}>{children}</Box>}
</Typography>
);
}
TabPanel.propTypes = {
children: PropTypes.node,
index: PropTypes.any.isRequired,
value: PropTypes.any.isRequired,
};
function a11yProps(index) {
return {
id: `simple-tab-${index}`,
'aria-controls': `simple-tabpanel-${index}`,
};
}
export default class Entities extends Component {
state = {
value: 0
}
handleChange = (event, newValue) => {
this.setState({value: newValue});
}
handleChangeIndex = index => {
this.setState({value: index});
}
render() {
const {value} = this.state;
return(
<div className="container-info">
<Grid container>
<div className="padding-top-4 padding-left-0">
<Paper>
<Tabs value={value} onChange={this.handleChange}>
<Tab label={<span className="font-bold">A</span>}/>
<Tab label={<span className="font-bold">B</span>}/>
<Tab label={<span className="font-bold">C</span>}/>
<Tab label={<span className="font-bold">D</span>}/>
<Tab label={<span className="font-bold">E Types</span>}/>
</Tabs>
</Paper>
<SwipeableViews>
<TabPanel value={value} index={0}>
<A />
</TabPanel>
<TabPanel value={value} index={1}>
<B />
</TabPanel>
<TabPanel value={value} index={2}>
<C />
</TabPanel>
<TabPanel value={value} index={3}>
<D />
</TabPanel>
<TabPanel value={value} index={4}>
<E />
</TabPanel>
</SwipeableViews>
</div>
</Grid>
</div>
);
}
}
}
如何解决此错误?
将您的元素包裹在 SwipeableViews 标签中。
<SwipeableViews>
<TabPanel value={value} index={0}>
<A />
</TabPanel>
<TabPanel value={value} index={1}>
<B />
</TabPanel>
</SwipeableViews>
将 react-swipeable-views
降级到 0.13.3
,使用 0.13.3 直到 0.13.6 修复了所有近期问题。issues
我正在尝试在我的 React 应用程序中使用 react-swipable-views
。我收到以下错误:-
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
我是这样导入的:
import SwipeableViews from "react-swipeable-views";
用法:
import React, { Component } from 'react';
import './../index.css';
import {
Tabs,
Tab,
Grid,
Paper,
Typography,
Box,
Icon
} from '@material-ui/core';
import PropTypes from 'prop-types';
import A from './components/A/A';
import B from './components/B/B';
import C from './components/C/C';
import D from './components/D/D';
import E from './components/E/E';
import SwipeableViews from "react-swipeable-views";
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}
>
{value === index && <Box p={3}>{children}</Box>}
</Typography>
);
}
TabPanel.propTypes = {
children: PropTypes.node,
index: PropTypes.any.isRequired,
value: PropTypes.any.isRequired,
};
function a11yProps(index) {
return {
id: `simple-tab-${index}`,
'aria-controls': `simple-tabpanel-${index}`,
};
}
export default class Entities extends Component {
state = {
value: 0
}
handleChange = (event, newValue) => {
this.setState({value: newValue});
}
handleChangeIndex = index => {
this.setState({value: index});
}
render() {
const {value} = this.state;
return(
<div className="container-info">
<Grid container>
<div className="padding-top-4 padding-left-0">
<Paper>
<Tabs value={value} onChange={this.handleChange}>
<Tab label={<span className="font-bold">A</span>}/>
<Tab label={<span className="font-bold">B</span>}/>
<Tab label={<span className="font-bold">C</span>}/>
<Tab label={<span className="font-bold">D</span>}/>
<Tab label={<span className="font-bold">E Types</span>}/>
</Tabs>
</Paper>
<SwipeableViews>
<TabPanel value={value} index={0}>
<A />
</TabPanel>
<TabPanel value={value} index={1}>
<B />
</TabPanel>
<TabPanel value={value} index={2}>
<C />
</TabPanel>
<TabPanel value={value} index={3}>
<D />
</TabPanel>
<TabPanel value={value} index={4}>
<E />
</TabPanel>
</SwipeableViews>
</div>
</Grid>
</div>
);
}
}
}
如何解决此错误?
将您的元素包裹在 SwipeableViews 标签中。
<SwipeableViews>
<TabPanel value={value} index={0}>
<A />
</TabPanel>
<TabPanel value={value} index={1}>
<B />
</TabPanel>
</SwipeableViews>
将 react-swipeable-views
降级到 0.13.3
,使用 0.13.3 直到 0.13.6 修复了所有近期问题。issues