Created
July 29, 2021 12:53
-
-
Save mizchi/f5c6e516896da10d63d9dd6119ca6676 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import ReactDOM from "react-dom"; | |
import { ChakraProvider, DarkMode, Button, LightMode } from "@chakra-ui/react"; | |
import type { ApplicationProps } from "../../shell/src/types"; | |
import { CacheProvider } from "@emotion/react"; | |
import createCache from "@emotion/cache"; | |
function Root(props: ApplicationProps) { | |
return ( | |
<> | |
<LightMode> | |
<Button>In Light Mode</Button> | |
</LightMode> | |
<DarkMode> | |
<Button>In Dark Mode(Broken)</Button> | |
</DarkMode> | |
</> | |
); | |
} | |
const run = (props: ApplicationProps) => { | |
const root = props.getRoot(); | |
const shadowRoot = root.attachShadow({ mode: "open" }); | |
const myCache = createCache({ | |
// @ts-ignore | |
container: shadowRoot, | |
key: "c", | |
}); | |
const rootElement = document.createElement("main"); | |
shadowRoot.appendChild(rootElement); | |
ReactDOM.render( | |
<React.StrictMode> | |
<CacheProvider value={myCache}> | |
<ChakraProvider> | |
<DarkMode> | |
<Root {...props} /> | |
</DarkMode> | |
</ChakraProvider> | |
</CacheProvider> | |
</React.StrictMode>, | |
rootElement | |
); | |
return () => { | |
ReactDOM.unmountComponentAtNode(root); | |
}; | |
}; | |
export default run; |
Thanks, love ya ❤️
Oh man, this is the only working code example I've found of getting ChakraUI to work with the shadow DOM. Thanks so much!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks bro! Helped me out 🙏