Hi, better than explain, let me show you.
What's happening:

What I expected:

Environment information:
"@emotion/core": "^10.0.10",
"@emotion/styled": "^10.0.11",
"react": "^16.8.6",
"react-dom": "^16.8.6",
How can I use emotion/styled inside Webcomponents shadow dom.
// index.js
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
class XComponent extends HTMLElement {
connectedCallback() {
const mountPoint = document.createElement('div');
this.attachShadow({ mode: 'open' }).appendChild(mountPoint);
ReactDOM.render(<App />, mountPoint);
}
}
customElements.define('x-component', XComponent);
// App.js
import React from 'react';
import styled from '@emotion/styled';
function App() {
return <StyledComponent>ok</StyledComponent>;
}
export default App;
const StyledComponent = styled.div`
background: red;
`;
// index.html
<!DOCTYPE html>
<html lang="en">
<body>
<x-component></x-component>
</body>
</html>
Hey,
According to the docs, you need to use createEmotion or createCache and assign a container for emotion to render your styles into.
thanks @diffidentDude, it does the trick !! 馃憤
Most helpful comment
Hey,
According to the docs, you need to use createEmotion or createCache and assign a container for emotion to render your styles into.