Can somebody help with a jscodeshift to convert all the named imports to default import for MUI V5 (React + Typescript) Current code
import { Button, TextField } from '@mui/material';
Expected output
import Button from '@mui/material/Button';
import TextField from '@mui/material/TextField';
I whipped this up using Codemod Studio (codemod share link):
This should do what you are looking for.
I haven't tested it outside of codemod studio, so make sure you do so. To easily deploy it, you can export it to Intuita VS Code Extension in the top right corner (as shown here @2:06).
You can also run the codemod using jscodeshift cli as usual, but I find the extension to be easier for me.
By looking at the exported code, the codemod simply looks for the
@mui/material
import source and replaces it with the imports you need.You can create and debug simple codemods like this using Codemod Studio. See here how to create your own codemods. Also, you can create them natively using jscodeshift API, but I find this method to be easier.
Disclosure: I'm affiliated with Intuita. By no means this is self-promotion. This is how I create codemods for simple use cases like this. Not all codemods can be made with Codemod Studio at the current time, but it can go a long way for simple changes and refactors like this.