Socket
Book a DemoInstallSign in
Socket

@valu/react-inline

Package Overview
Dependencies
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@valu/react-inline

Tool for writing inline styles and scripts in React.

latest
npmnpm
Version
2.0.0
Version published
Maintainers
2
Created
Source

React Inline

Tool for writing inline styles and scripts in React.

Often used in Next.js _document.tsx files.

Install

npm install @valu/react-inline

Inline Styles

Add inline style tags with syntax highlighting via the css template tag and the VSCode extension.

Font CSS example:

import { InlineStyle, css } from "@valu/react-inline";

const fontCSS = css`
    @font-face {
        font-family: "ApexNewBookRegular";
        src: url("/fonts/ApexNew-Book.otf");
        font-display: swap;
    }
    @font-face {
        font-family: "ApexNewBookBold";
        src: url("/fonts/ApexNew-Bold.otf");
        font-display: swap;
    }
    @font-face {
        font-family: "ApexNewBookLight";
        src: url("/fonts/ApexNew-Light.otf");
        font-display: swap;
    }
`;

<InlineStyle css={fontCSS} />;

Alternative API when you have a colliding css template tags (ex. with react-bemed):

<InlineStyle
    css={(css) => css`
        body,
        html {
            padding: 0;
            margin: 0;
        }
    `}
/>

Inline Script

Execute the given function in a inline <script> tag

import { InlineScript } from "@valu/react-inline";

<InlineScript
    exec={function () {
        console.log("Inline script! ");
    }}
/>;

With arguments

<InlineScript
    args={["World"]}
    exec={function (name: string) {
        console.log("Hello " + name);
    }}
/>

Caveats:

  • The script is inlined with Function#toString() so you cannot reference variables in the parent closures.

  • If the script is SSR rendered (ex. in Next.js _document.tsx), it might not get transpiled. It's better to avoid modern JavaScript syntax when legacy browser support is required

    • TypeScript types are stripped always though.
  • The args are serialized with JSON.stringify()

Raw Inline Script

A tiny wrapper for dangerouslySetInnerHTML. Use for 3rdparty embeding such as Google Tag Manager.

<InlineScript.Raw
    code={`(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
            new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
            j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
            'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
            })(window,document,'script','dataLayer','***');`}
/>

FAQs

Package last updated on 18 May 2021

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.