npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-qztray

v1.0.0

Published

React hooks for seamless integration with QZ Tray (qz.io)

Readme

react-qztray

React hooks for seamless integration with QZ Tray — the browser-to-desktop print connector.

npm version license


Requirements

  • QZ Tray desktop application running on the user's machine (download)
  • React 18 or 19
  • A backend endpoint to sign QZ Tray requests (required for production use)

Tutorials


Installation

npm install react-qztray
# or
pnpm add react-qztray

Quick start

1. Wrap your app with QzTrayProvider

import { QzTrayProvider } from 'react-qztray';

export const Root = () => (
  <QzTrayProvider
    certificate="-----BEGIN CERTIFICATE-----\nYOUR_CERT_HERE\n-----END CERTIFICATE-----"
    signatureAlgorithm="SHA512"
    signaturePromise={(toSign) => (resolve) => {
      fetch('/api/sign', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ toSign }),
      })
        .then((res) => res.text())
        .then(resolve);
    }}
  >
    <App />
  </QzTrayProvider>
);

2. Connect and print

import { useQzTray, useQzPrint } from 'react-qztray';

const PrintButton = () => {
  const { isConnected, connect } = useQzTray();
  const { print, isPrinting } = useQzPrint();

  const handlePrint = async () => {
    if (!isConnected) await connect();

    print({
      printer: 'ZDesigner',
      config: { size: { width: 100, height: 150 }, units: 'mm' },
      data: [{ type: 'pixel', format: 'html', flavor: 'plain', data: '<h1>Hello!</h1>' }],
    });
  };

  return (
    <button onClick={handlePrint} disabled={isPrinting}>
      {isPrinting ? 'Printing...' : 'Print'}
    </button>
  );
};

API

QzTrayProvider

Provides QZ Tray context to all child hooks. Place it at the root of your app.

| Prop | Type | Required | Description | |---|---|---|---| | certificate | string \| (() => Promise<string>) | ✓ | Public PEM certificate from QZ Tray's signing tool. Accepts a string or an async function that fetches it. | | signaturePromise | PromiseFactory | ✓ | Factory function that signs the request. Should call your backend. | | signatureAlgorithm | "SHA1" \| "SHA256" \| "SHA512" | | Signing algorithm. Defaults to "SHA512". | | wsOptions | ConnectOptions | | WebSocket connection options (host, port, keepAlive, retries, delay). | | autoConnect | boolean | | Connect to QZ Tray automatically on mount. Defaults to false. | | onConnect | () => void | | Called when the connection is established. | | onDisconnect | () => void | | Called when the connection is closed. | | onError | (error: unknown) => void | | Called on connection error. |


useQzTray

Access connection state and controls. Must be used inside QzTrayProvider.

const { isConnected, isConnecting, error, connect, disconnect } = useQzTray();

| Return | Type | Description | |---|---|---| | isConnected | boolean | Whether QZ Tray is currently connected. | | isConnecting | boolean | Whether a connection attempt is in progress. | | error | unknown | Last connection error, or null. | | connect | () => Promise<void> | Open the WebSocket connection. | | disconnect | () => Promise<void> | Close the WebSocket connection. |


useQzPrint

Send print jobs to any printer visible to QZ Tray. Must be used inside QzTrayProvider.

const { print, isPrinting, error } = useQzPrint();

| Return | Type | Description | |---|---|---| | print | (options: IPrintOptions) => Promise<void> | Send a print job. Connects automatically if not connected. | | isPrinting | boolean | Whether a print job is in progress. | | error | unknown | Last print error, or null. |

IPrintOptions

| Option | Type | Required | Description | |---|---|---|---| | printer | string | ✓ | Printer name as it appears in the OS. | | data | PrintData[] | ✓ | Array of print data objects. | | config | PrinterOptions | | Paper size, units, density, orientation, etc. | | autoDisconnect | boolean | | Disconnect after the job completes. Defaults to true. |


Examples

See the examples/ directory for complete usage examples:


Playground

A Vite dev app is included for local testing.

pnpm install
pnpm playground

Open http://localhost:5173, paste your certificate and signature endpoint, and send test print jobs directly from the browser.


Contributing

Contributions are more than welcome! Whether it's a bug report, feature request, or a pull request — all input is appreciated.

  1. Fork the repo and create your branch from main
  2. Install dependencies with pnpm install
  3. Make your changes and add tests where applicable
  4. Run pnpm lint, pnpm typecheck, and pnpm test before submitting
  5. Open a pull request

If you're unsure about something, feel free to open an issue first to discuss it.


License

MIT © Juliusz Kowalewski