I am using MUI components in a react app, and to test it I directly copied sample code from the documentation.
Doing so threw 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.
Based on research I did to solve the issue, it seems to stem from bad import statements and mixing up export default
components with regular exports. But the import statements I am using are exactly as they should be and directly off documentation, so I am confused.
This is the sample code used:
import { styled } from '@mui/material/styles';
import Box from '@mui/material/Box';
import Paper from '@mui/material/Paper';
import Grid from '@mui/material/Grid';
const Item = styled(Paper)(({ theme }) => ({
backgroundColor: theme.palette.mode === 'dark' ? '#1A2027' : '#fff',
...theme.typography.body2,
padding: theme.spacing(1),
textAlign: 'center',
color: theme.palette.text.secondary,
}));
export default function BasicGrid() {
return (
<Box sx={{ flexGrow: 1 }}>
<Grid container spacing={2}>
<Grid item xs={8}>
<Item>xs=8</Item>
</Grid>
<Grid item xs={4}>
<Item>xs=4</Item>
</Grid>
<Grid item xs={4}>
<Item>xs=4</Item>
</Grid>
<Grid item xs={8}>
<Item>xs=8</Item>
</Grid>
</Grid>
</Box>
);
}
Directly copying this threw the error.