How to import MUI component in different name?

Viewed 396

Really short question, how do I import Table from MUI in a different name, as the name of my components is Table.js and there is a conflict because the way you import MUI Table is like this:

import Table from "@mui/material/Table";

and obviously there is a conflict because then there are two elements in a component that have Table identifier.

Is there any way to import Table in a different name?

3 Answers
import { Table as CustomTableName } from "@mui/material";

or

import CustomTableName from "@mui/material/Table";
import {Table as YourTableName} from "@mui/material/Table";

You're using default import, the name of the component can be anything you want, the convention is to use MuiComponent if there are duplicated names in your file:

import { styled } from '@mui/material/styles';
import MuiTable from "@mui/material/Table";

const Table = styled(MuiTable)(...);
Related