Skip to content

Instantly share code, notes, and snippets.

@christianalfoni
Created April 27, 2020 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christianalfoni/4a6c32fcc7c2307e9ebbb406c4c19653 to your computer and use it in GitHub Desktop.
Save christianalfoni/4a6c32fcc7c2307e9ebbb406c4c19653 to your computer and use it in GitHub Desktop.
next js
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>
)
}
}
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 {
}
}
}
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 }
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