reactjsgoogle-chrome-extensionmaterial-ui

Plasmo framework and Material UI in content UI script


I'm using Plasmo to make a browser extension with React and I would like to utilize the MUI library. I am able to get the components to work in the popup script, however, in my content UI scripts, I am unable to get the styling to show up (i.e. I just get a plain HTML button instead of a MUI-styled button).

How can I get the correct styles from the MUI components in my component script?


Solution

  • Check out this example

    Here's the outline of what you need to do:

    npm i @emotion/cache @emotion/react

    import createCache from "@emotion/cache"
    import { CacheProvider } from "@emotion/react"
    
    const styleElement = document.createElement("style")
    
    const styleCache = createCache({
      key: "plasmo-mui-cache",
      prepend: true,
      container: styleElement
    });
    
    export const getStyle = () => styleElement;
    
    const MuiThemedContent = () => (
      <CacheProvider value={styleCache}>
        ... mui component
      </CacheProvider>
    );
    export default MuiThemedContent;