3

I'm trying to use react-swipable-views in my react application. I'm getting the following error :- Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.

I've imported it as follows:

import SwipeableViews from "react-swipeable-views";

Usage:


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>
        );
    }
}

 }

How do I resolve this error?

cyberman123
  • 412
  • 5
  • 14

3 Answers3

4

Downgrade react-swipeable-views to 0.13.3,using 0.13.3 until 0.13.6 fixes all recent issues.issues

Alex
  • 3,941
  • 1
  • 17
  • 24
0

If you're facing a version issue with React, you can uninstall the original package and can install this one:

react-swipeable-views-react-18-fix (Link below)

https://www.npmjs.com/package/react-swipeable-views-react-18-fix

It will work!

aliezaheer
  • 59
  • 1
  • 9
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 21 '23 at 14:04
-2

Wrap your elements in the SwipeableViews tag.

<SwipeableViews>

 <TabPanel value={value} index={0}>
    <A />
 </TabPanel>
 <TabPanel value={value} index={1}>
    <B />
 </TabPanel>
</SwipeableViews>
Mehrnoosh
  • 879
  • 2
  • 12
  • 27