Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update ssr and nextjs #771

Merged
merged 4 commits into from
Jan 14, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ Turn on/off automatic vendor prefixing (default: `true`)
- Dynamic styles and themes support
- CSS Preprocessing via Plugins

## Using in Next.js

Next.js 12+ includes SWC compiler and transformer. You don't have to configure it in babel plugins.
huozhi marked this conversation as resolved.
Show resolved Hide resolved

## How It Works

The example above transpiles to the following:
Expand Down Expand Up @@ -334,6 +338,13 @@ Please keep in mind that constants defined outside of the component scope are tr

## Server-Side Rendering

`styled-jsx` v5 introduced `StyledRegistry` component and `useStyleRegistry` hook to let you scope styles rendering in each SSR render to keep concurrent-safe.

- `registry.styles()` will return the array of react components for style tags.
- `registry.flush()` can clean the existing styles in the registry, it's optional for SSR when you have a standalone registry for each SSR render.

> Next.js 12 integrates with `styled-jsx` v5 and manages the registry for you.

```jsx
import React from 'react'
import ReactDOM from 'react-dom/server'
Expand All @@ -343,7 +354,6 @@ import App from './app'
function Styles() {
const registry = useStyleRegistry()
const styles = registry.styles()
registry.flush()
return <>{styles}</>
}

Expand Down