Styled Components 💅🏾¶
CSS in JS
Why
- Scoped CSS
uses template literals
Global styles¶
const GlobalStyles = createGlobalStyle`
    @font-face {
    ...
    }
    :root {
        --black: #393939
        --grey: #393939
        --gray: var(--grey)
    }
`;
const Page = () => (
    <div>
        <GlobalStyles />
        <Header />
        <InnerStyles>{children}</InnerStyles>
    </div>
);
Next JS and Styled components¶
- https://styled-components.com/docs/advanced#server-side-rendering
- https://courses.wesbos.com/account/access/5fbfe7466ef8b359b1d11782/view/505027401
- 
The server renders things - styled components generates random IDs
 
- and client renders again- styled components renders a different random ID
 
Solution: ServerStyleSheet¶
Next JS hook: getInitialProps
- wait until the method has been resolved
- then it sends the data (server --> browser)
  
    
      Last update:
      2023-04-24