# @kachkaev/react-inline-js

> This package exports a React component you can use in your [Custom Next.js Document](https://nextjs.org/docs/advanced-features/custom-document). It accepts a string with the JavaScript code and minifies it with [`terser`](https://www.npmjs.com/package/ter

Latest version **0.4.1** (published 2023-06-03) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @kachkaev/react-inline-js
pnpm add @kachkaev/react-inline-js
yarn add @kachkaev/react-inline-js
bun add @kachkaev/react-inline-js
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.4.1 |
| Published | 2023-06-03 |
| First published | 2020-08-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 2 |
| Unpacked size | 6.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Alexander Kachkaev |
| Maintainers | kachkaev |
| Keywords | document, inline, next.js, next, script, ssr, terser |

## Links

- npm: https://www.npmjs.com/package/@kachkaev/react-inline-js
- Repository: https://github.com/kachkaev/routine-npm-packages
- Homepage: https://github.com/kachkaev/routine-npm-packages#readme
- Issues: https://github.com/kachkaev/routine-npm-packages/issues
- npm.io page: https://npm.io/package/@kachkaev/react-inline-js

## Dependencies (2)

- [mem](https://npm.io/package/mem.md) ^9.0.2
- [terser](https://npm.io/package/terser.md) ^4.8.1

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.4.1 (latest) — 2023-06-03
- 0.4.0 — 2022-01-03
- 0.3.0 — 2021-12-31
- 0.2.0 — 2020-10-18
- 0.1.0 — 2020-08-29

## README

# React Inline JS

This package exports a React component you can use in your [Custom Next.js Document](https://nextjs.org/docs/advanced-features/custom-document).
It accepts a string with the JavaScript code and minifies it with [`terser`](https://www.npmjs.com/package/terser).
The result is memoised.

A common use case for the component would be the Google Analytics initialisation script the dark mode enabler – see [example repo](https://github.com/kachkaev/njt).

## Usage

```tsx
// pages/_document.js

import Document, { Html, Head, Main, NextScript } from "next/document";
import { InlineJs } from "@kachkaev/react-inline-js";

class MyDocument extends Document {
  static async getInitialProps(ctx) {
    const initialProps = await Document.getInitialProps(ctx);
    return { ...initialProps };
  }

  render() {
    return (
      <Html>
        <Head />
        <body>
          <InlineJs
            code={`
              // This code will be minified

              const message = "Hello world"
              console.log(message);
          `}
          />
          <Main />
          <NextScript />
        </body>
      </Html>
    );
  }
}

export default MyDocument;
```

Output for `InlineJs` component:

<!-- prettier-ignore -->
```html
<script>const message="Hello world";console.log(message);</script>
```

Note that using `<InlineJS />` is not allowed on the client, i.e. anywhere except `_document.js`.
To prevent accidental inclusion of `terser` in the client bundle, an error will be thrown.

It is not allowed to include `</script` in any part of your code as this may result a corrupt page.
If this string is

---
_Source: https://npm.io/package/@kachkaev/react-inline-js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
