Closed siriwatknp closed 4 months ago
Render any component with sx usage like this will throw an Error Cannot read property 'applyStyles' of undefined:
sx
Cannot read property 'applyStyles' of undefined
<Box sx={theme => ({ backgroundSize: 'cover', backgroundPosition: 'center', minHeight: 280, backgroundImage: 'var(--Image-light)', ...theme.applyStyles('dark', { backgroundImage: 'var(--Image-dark)', }), })}
The correct syntax for using theme from sx prop is to declare a parameter, not object pattern ({ theme })
theme
({ theme })
The sx prop should work with sx={theme => …}
sx={theme => …}
I am working on a codemod for transforming sx prop and I stumbled on this error.
npx @mui/envinfo
Search keywords: sx theme
Steps to reproduce
Render any component with
sx
usage like this will throw an ErrorCannot read property 'applyStyles' of undefined
:Current behavior
The correct syntax for using
theme
fromsx
prop is to declare a parameter, not object pattern({ theme })
Expected behavior
The
sx
prop should work withsx={theme => …}
Context
I am working on a codemod for transforming
sx
prop and I stumbled on this error.Your environment
``` Don't forget to mention which browser you used. Output from `npx @mui/envinfo` goes here. ```npx @mui/envinfo
Search keywords: sx theme