# npm package (https://notert.io/docs/widget/npm-package)

Last updated 2026-11-22

`@notert/widget` loads the same widget the snippet does, from your own code rather than your page's HTML. Every call is typed, so your editor completes each screen, event and option, and a React hook keeps your own Help button in step with the widget.

```sh
npm install @notert/widget
```

## Load it [#load-it]

Call `loadNotert` once in the browser with your workspace's id, which the install guide writes into your snippet as the first value of `init`:

```ts
import { loadNotert } from "@notert/widget";

loadNotert({ workspaceId: "YOUR_WORKSPACE_ID", theme: "page" });
```

It takes every option `init` does, such as `launcher: false` for [your own button](/docs/widget/javascript-api#your-own-button) or `language`, and loads the widget's script once however often it's called. On a server it does nothing, so a component that renders on both sides can call it.

Use it in place of the snippet, not beside it. A page that has both still draws one widget, and only the first `init` counts.

## Call it [#call-it]

```ts
import { notert } from "@notert/widget";

notert.identify(await fetchNotertToken());
notert.open({ screen: "new", text: "I found a bug: " });
notert.on("conversation:started", ({ conversationId }) => {
  analytics.track("Support conversation started", { conversationId });
});
```

`notert` has every call in the [JavaScript reference](/docs/widget/javascript-api): `init`, `identify`, `open`, `close`, `toggle`, `on`, `off`, `appearance`, `suggest`, `context`, `track`, `hideLauncher`, `showLauncher` and `shutdown`. Each works before the widget has loaded, which plays them back in order once it has, and calls the same widget whether `loadNotert` or a pasted snippet put it on the page.

The types it exports, such as `NotertPlace`, `NotertEvents` and `NotertInitOptions`, name what each call takes, so a misspelled screen or event fails your build rather than warning in the browser's console.

## In React [#in-react]

```tsx
import { NotertProvider, useNotert } from "@notert/widget/react";

export function App() {
  return (
    <NotertProvider workspaceId="YOUR_WORKSPACE_ID" launcher={false} theme="page">
      <HelpButton />
    </NotertProvider>
  );
}

function HelpButton() {
  const { toggle, isOpen, unseen, online } = useNotert();
  return (
    <button type="button" aria-expanded={isOpen} onClick={() => toggle()}>
      Help
      {unseen > 0 ? (
        <span className="badge">{unseen}</span>
      ) : (
        online && (
          <span className="dot">
            <span className="sr-only">Online</span>
          </span>
        )
      )}
    </button>
  );
}
```

- **`NotertProvider`** loads the widget once as it mounts, with the props it mounts with. Later props change nothing, and unmounting it leaves the widget on the page: call `notert.shutdown()` to take it off.
- **`useNotert()`** gives `open`, `close` and `toggle`, and keeps `isOpen`, `unseen` and `online` current through the widget's [`change` event](/docs/widget/javascript-api#on-and-off). Before the widget has loaded, it reads closed, with nothing unseen and no one online.

`useNotert` works anywhere on the page, under the provider or not, as long as something loads the widget. React 18 or later is needed only for this part.

`toggle` and `open` take a screen too, as [`open`](/docs/widget/javascript-api#open-it-on-a-screen) does, so a menu of your own can open each part: `onClick={() => open({ screen: "new", text: "I found a bug: " })}`.

### In Next.js [#in-nextjs]

`NotertProvider` and `useNotert` use React state, so in the App Router they run in a client component. Put the provider in a file of its own marked `"use client"`, and wrap your root layout's children in it:

```tsx
// app/notert-provider.tsx
"use client";

import { NotertProvider } from "@notert/widget/react";

export function Notert({ children }: { children: React.ReactNode }) {
  return (
    <NotertProvider workspaceId="YOUR_WORKSPACE_ID" theme="page">
      {children}
    </NotertProvider>
  );
}
```

```tsx
// app/layout.tsx
import { Notert } from "./notert-provider";

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>
        <Notert>{children}</Notert>
      </body>
    </html>
  );
}
```

A component that calls `useNotert()`, such as your Help button, is marked `"use client"` too. The provider adds the widget's script as it mounts in the browser, so a page rendered on the server carries nothing of it.

## Tell it who signed in [#tell-it-who-signed-in]

```tsx
import { notert } from "@notert/widget";
import { useEffect } from "react";

export function NotertIdentity({ user }: { user: { notertToken: string } | null }) {
  useEffect(() => {
    // A token your server signed for this user, or null once they've signed out.
    notert.identify(user ? user.notertToken : null);
  }, [user]);
  return null;
}
```

See [single-page apps](/docs/widget/single-page-apps#tell-it-who-signed-in) for when to call it, and [identify your signed-in users](/docs/signed-in-users/identify-users) for the token.

<Note>
The package loads the widget's script from Notert, as the snippet does, so your site picks up each
new release on its next load. Your [Content Security Policy](/docs/widget/content-security-policy)
needs the same sources, apart from the inline snippet, which the package doesn't use.
</Note>