Skip to content

Commit

Permalink
polish
Browse files Browse the repository at this point in the history
  • Loading branch information
phonzammi committed Dec 15, 2024
1 parent c06d341 commit 77aa376
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
11 changes: 5 additions & 6 deletions packages/vike-react-styled-jsx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ Integrates [styled-jsx](https://github.com/vercel/styled-jsx) to your [`vike-rea
}
```

3. Add `styled-jsx/babel` to plugins in your babel configuration:
3. Add the `styled-jsx`'s Babel plugin:
```js
// vite.config.js
import { defineConfig } from "vite"
import react from "@vitejs/plugin-react"
import vike from "vike/plugin"

export default defineConfig({
export default {
plugins: [
vike(),
react({
Expand All @@ -41,15 +40,15 @@ Integrates [styled-jsx](https://github.com/vercel/styled-jsx) to your [`vike-rea
},
}),
],
});
};
```

4. You can now use styled-jsx at any of your components.
```jsx
function SomeComponent() {
return (
<div>
<p>only this paragraph will get the style :)</p>
<p>Only this paragraph will get the style.</p>

<style jsx>{`
p {
Expand All @@ -68,7 +67,7 @@ Integrates [styled-jsx](https://github.com/vercel/styled-jsx) to your [`vike-rea

## Settings

`vike-react-styled-jsx` provides a configuration `+styledJsx` that adds a [CSP nonce](https://github.com/vercel/styled-jsx#content-security-policy) meta tag and injects the nonce into the style tag.
`vike-react-styled-jsx` provides a configuration `+styledJsx` to set the [CSP nonce for `styled-jsx`](https://github.com/vercel/styled-jsx#content-security-policy).

> [!NOTE]
> You also need to set a `<meta property="csp-nonce" content={nonce} />` tag with the same nonce.
Expand Down
2 changes: 1 addition & 1 deletion packages/vike-react-styled-jsx/Wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function Wrapper({ children }: { children: ReactNode }) {
if (pageContext.config.styledJsx === null) return <>{children}</>

if ('styledJsx' in pageContext) {
return <StyleRegistry registry={pageContext.styledJsx?.registry}>{children}</StyleRegistry>
return <StyleRegistry registry={pageContext.styledJsx!.registry}>{children}</StyleRegistry>
}
return <>{children}</>
}
2 changes: 1 addition & 1 deletion packages/vike-react-styled-jsx/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const config = {
env: { server: true },
},
Wrapper: {
env: { server: true, client: false },
env: { server: true },
},
},
} satisfies Config
Expand Down

0 comments on commit 77aa376

Please sign in to comment.