TypeError: Cannot read properties of null (reading 'scrollTop') Material UI
Asked Answered
P

2

9

I have migrated MUI-4 to MUI-5 and facing this error. Any Help?

Petronille answered 20/12, 2022 at 11:10 Comment(0)
P
31

I discovered that I was feeding my own component inside the SnackBar. When I wrapped the content of SnackBar in a div, it was fixed. As the error message says "Expected an element that can hold a ref," SnackBar's child needs to be an element that can hold a ref, e.g. a div.

Before: <SnackBar> <MyAlert/> </SnackBar>

After: <SnackBar><div> <MyAlert/> </div> </SnackBar>

Thanks

Petronille answered 20/12, 2022 at 11:10 Comment(1)
Absolutely bang on. Thank you.Savagism
T
0

I faced this error when I used animation components like <Fade> | <Slide> | <Grow>. I didn't had a troubles in react component, but in jest when I tested react components that used listed above components from MUI.

For prevent this error I used jest.mock:

jest.mock('@mui/material/Fade', () =>
    forwardRef(function FadeRef({children, ...other}: FadeProps, ref: ForwardedRef<HTMLDivElement>) {
        return (
            <Box ref={ref} {...other}>
                {children}
            </Box>
        );
    }),
);

Maybe it will help someone.

Thibodeaux answered 25/7, 2024 at 6:17 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.