Skip to content

Instantly share code, notes, and snippets.

@lmosele
Created October 4, 2019 14:30
Show Gist options
  • Save lmosele/bf77242c0f69e5fd8b90e17f347dab66 to your computer and use it in GitHub Desktop.
Save lmosele/bf77242c0f69e5fd8b90e17f347dab66 to your computer and use it in GitHub Desktop.
Styled Components with React Frame
import React from "react"; // "react": "^16.8.6",
import Frame, { FrameContextConsumer } from "react-frame-component"; // "react-frame-component": "^4.1.0",
import { StyleSheetManager, withTheme, ThemeProvider } from "styled-components"; // "styled-components": "^3.3.3",
export default withTheme(props => {
const { theme, style = {}, children, ...rest } = props;
return (
<Frame
style={{
display: "block",
overflow: "scroll",
border: 0,
...style
}}
{...rest}
>
<FrameContextConsumer>
{frameContext => (
<StyleSheetManager target={frameContext.document.head}>
{theme ? (
<ThemeProvider theme={theme}>{children}</ThemeProvider>
) : (
children
)}
</StyleSheetManager>
)}
</FrameContextConsumer>
</Frame>
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment