Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vike-react-styled-jsx

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vike-react-styled-jsx

Integrates [styled-jsx](https://github.com/vercel/styled-jsx) to your [`vike-react`](https://vike.dev/vike-react) app.

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
decreased by-50%
Maintainers
0
Weekly downloads
 
Created
Source

vike-react-styled-jsx

Integrates styled-jsx to your vike-react app.

Installation
Settings
Version history
What it does
See also


Installation

  1. npm install vike-react-styled-jsx styled-jsx

  2. Extend +config.js:

    // pages/+config.js
    
    import vikeReact from "vike-react/config"
    import vikeReactStyledJsx from "vike-react-styled-jsx/config"
    
    export default {
      // ...
      extends: [vikeReact, vikeReactStyledJsx]
    }
    
  3. Add styled-jsx's Babel plugin:

    // vite.config.js
    import react from "@vitejs/plugin-react"
    import vike from "vike/plugin"
    
    export default {
      plugins: [
       vike(),
       react({
         babel: {
           plugins: [["styled-jsx/babel"]]
         }
       })
     ]
    }
    
  4. You can now use styled-jsx at any of your components.

    function SomeComponent() {
      return (
        <div>
         <p>Only this paragraph will get the style.</p>
         
         <style jsx>{`
           p {
             color: red;
           }
         `}</style>
        </div>
      )
    }
    

[!NOTE] The vike-react-styled-jsx extension requires vike-react.


Settings

vike-react-styled-jsx provides a configuration +styledJsx to set the CSP nonce for styled-jsx.

[!NOTE] You need to set a <meta property="csp-nonce" content={nonce} /> tag with the same nonce.

// pages/+styledJsx.js
export { styledJsx }

import nanoid from 'nanoid'

const styledJsx = {
  nonce: Buffer.from(nanoid()).toString('base64') //ex: N2M0MDhkN2EtMmRkYi00MTExLWFhM2YtNDhkNTc4NGJhMjA3
}

You can remove the vike-react-styled-jsx integration from some of your pages:

// pages/about/+styledJsx.js

export const styledJsx = null

For full customization consider ejecting.

[!NOTE] Consider making a Pull Request before ejecting.


What it does

The vike-react-styled-jsx extension allows you to use styled-jsx without FOUC.

It collects the page's styles during SSR and injects them in the HTML, ensuring that styles are applied early (before even JavaScript starts loading).

You can learn more at:

For more details, have a look at the source code of vike-react-styled-jsx (which is small).


See also

FAQs

Package last updated on 28 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc