Material-Ui Makestyles Cannot Read Property 'Down' of Undefined

Material-UI makeStyles cannot read property 'down' of undefined

Replace

import { makeStyles } from "@material-ui/styles";

with

import { makeStyles } from "@material-ui/core/styles";

makeStyles from "@material-ui/core/styles" is a wrapper hook of the other one. This wrapper add a default theme if you don't provide one in ThemeProvider. Source.

MUI - makeStyles - Cannot read properties of undefined

Since you're using v5, change your ThemeProvider, createTheme and makeStyles import path from:

import { ThemeProvider, createTheme, makeStyles } from "@material-ui/core/styles";

To:

import { ThemeProvider, createTheme } from "@mui/material/styles";
import { makeStyles } from "@mui/styles";

@material-ui/core is v4 package and @mui/material is the v5 equivalent. The API from the 2 versions are not compatible. In v5, makeStyles is also moved to a legacy package called @mui/styles, if you are using MUI v5 in a new project, you should switch completely to styled/sx API as recommended by the MUI team.

Related answers

  • Difference between @mui/material/styles and @mui/styles?
  • Cannot use palette colors from MUI theme
  • MUI createTheme is not properly passing theme to MUI components

MaterialUI 5 : TypeError: Cannot read properties of undefined (reading 'create')

Just ran into this myself. You can import createTheme from @mui/material/styles or @mui/system, but they do slightly different things:

You can use the utility coming from the @mui/system package, or if you are using @mui/material, you can import it from @mui/material/styles. The difference is in the default theme that is used (if no theme is available in the React context).

The one from @mui/material/styles is smart enough to fill in gaps in the active theme from the default MUI theme. So if you're using @mui/material, then use @mui/material/styles.

I am getting (TypeError: Cannot read property 'down' of undefined)

maybe try replacing

import { makeStyles } from "@material-ui/styles";

with

import { makeStyles } from "@material-ui/core/styles";

MUI error: Cannot read properties of undefined (reading 'drawer')

It's strange but solution is reinstalling all MUI packages



Related Topics



Leave a reply



Submit