Introduction
This is a reference for upgrading your site from Material UI v3 to v4. While there’s a lot covered here, you probably won’t need to do everything for your site.Looking for the v3 docs? You can find the latest version here.
Why you should migrate
Material UI v4 introduced several improvements over v3:- React Hooks support - All components now support Hooks
- Improved performance - Smaller bundle sizes and faster rendering
- Better TypeScript - Enhanced type definitions
- New styling solution - Improved JSS integration
- Accessibility improvements - Better ARIA support
Updating your dependencies
Update Material UI version
Update yourpackage.json to use the latest version of Material UI:
Update React version
The minimum required version of React was increased fromreact@^16.3.0 to react@^16.8.0. This allows us to rely on Hooks (we no longer use the class API).
Update Material UI Styles version
If you were previously using@material-ui/styles with v3 you need to update your package.json:
Breaking changes
Core
- Every component forwards their ref using
React.forwardRef(). This affects the internal component tree and display name. - The
innerRefprop no longer returns a ref to the instance but a ref to its root component.
Styles
- Material UI depends on JSS v10. JSS v10 is not backward compatible with v9. Make sure JSS v9 is not installed in your environment.
- The
StylesProvidercomponent replaces theJssProviderone. - Remove the first option argument of
withTheme():
- Rename
convertHexToRGBtohexToRgb:
Theme
- The
theme.palette.augmentColor()method no longer performs a side effect on its input color. To use it correctly, you have to use the returned value:
- You can safely remove the next variant from the theme creation:
theme.spacing.unitusage is deprecated. Use the new API:
Button
- Remove the deprecated button variants (flat, raised and fab):
Card
- Rename the
disableActionSpacingprop todisableSpacing:
Dialog
- Rename the
disableActionSpacingprop todisableSpacing:
- Use typography variant
body1instead ofsubtitle1forDialogContentText:
Divider
- Remove the deprecated
insetprop:
ExpansionPanel
- Rename the
CollapsePropsprop toTransitionProps:
Grid
- In order to support arbitrary spacing values, the spacing API has changed:
List
- Rework the list components to match the specification:
- The
ListItemAvatarcomponent is required when using an avatar - The
ListItemIconcomponent is required when using a left checkbox - The
edgeproperty should be set on the icon buttons
- The
denseno longer reduces the top and bottom padding of theListelement
Menu
- Remove the fixed height of the MenuItem. The padding and line-height are used by the browser to compute the height.
Modal
- The child needs to be able to hold a ref
- Remove the classes customization API for the Modal component (-74% bundle size reduction when used standalone)
event.defaultPreventedis now ignored. The new logic closes the Modal even ifevent.preventDefault()is called on the key down escape event
Paper
- Reduce the default elevation from 2 to 1:
Tabs
- Remove deprecated
fullWidthandscrollableprops:
TextField
- Remove the
InputLabelPropsclassesproperty:
Tooltip
- The child needs to be able to hold a ref
- Rename
disableTriggerFocustodisableFocusListener:
- Rename
disableTriggerHovertodisableHoverListener:
- Rename
disableTriggerTouchtodisableTouchListener:
Typography
- Remove the deprecated typography variants:
Container
Moved from@material-ui/lab to @material-ui/core:
TypeScript
value type
Normalizedvalue prop type for input components to use unknown. This affects InputBase, NativeSelect, OutlinedInput, Radio, RadioGroup, Select, SelectInput, Switch, TextArea, and TextField:
Codemod
We provide codemods to help with the migration:theme.spacing() API.