Created
April 27, 2020 18:17
-
-
Save christianalfoni/4a6c32fcc7c2307e9ebbb406c4c19653 to your computer and use it in GitHub Desktop.
next js
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 App from 'next/app' | |
import React from 'react' | |
import { createCss, TCss } from '@stitches/css' | |
import { Provider, config } from './css' | |
export default class MyApp extends App<{ serverCss: TCss<typeof config> }> { | |
render() { | |
const { Component, pageProps, serverCss } = this.props | |
return ( | |
<Provider css={serverCss || createCss(config)}> | |
<Component {...pageProps} /> | |
</Provider> | |
) | |
} | |
} |
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 { createCss } from '@stitches/css' | |
import Document from 'next/document' | |
import { config } from './css' | |
export default class MyDocument extends Document { | |
static async getInitialProps(ctx) { | |
const css = createCss(config) | |
const originalRenderPage = ctx.renderPage | |
try { | |
ctx.renderPage = () => | |
originalRenderPage({ | |
enhanceApp: (App) => (props) => <App {...props} serverCss={css} />, | |
}) | |
const initialProps = await Document.getInitialProps(ctx) | |
return { | |
...initialProps, | |
styles: ( | |
<> | |
{initialProps.styles} | |
{css.getStyles().map((css, index) => ( | |
<style key={index}>{css}</style> | |
))} | |
</> | |
), | |
} | |
} finally { | |
} | |
} | |
} |
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 { createConfig } from '@stitches/css' | |
import { createStyled } from '@stitches/styled' | |
const config = createConfig({ | |
tokens: { | |
colors: { | |
RED: 'tomato', | |
}, | |
}, | |
}) | |
const { Provider, styled, useCss } = createStyled<typeof config>() | |
export { config, Provider, styled, useCss } |
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 { styled } from './css' | |
const Header = styled.h1(css => css.color('RED')) | |
export default function Home() { | |
return <Header>Hello world</Header> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment