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

@pwa-platform/react

v0.4.0

Published

React 19 binding for PWA Platform.

Readme

@pwa-platform/react

React 19 binding for PWA Platform. PwaProvider owns one browser lifecycle facade for its subtree, usePwa() exposes install/update state and actions, and an optional accessible update notice handles the confirmation flow. Configure build artifacts separately with @pwa-platform/vite.

Install

npm install @pwa-platform/react @pwa-platform/vite

Add @pwa-platform/vite/virtual to compilerOptions.types, then mount the provider:

// main.tsx
import config from "virtual:pwa-config";
import { PwaProvider } from "@pwa-platform/react";
import { createRoot } from "react-dom/client";
import { App } from "./App";

createRoot(document.getElementById("root")!).render(
  <PwaProvider config={config} updateCheck={{ intervalMs: 30 * 60_000 }}>
    <App />
  </PwaProvider>,
);

Register from a browser effect, normally only in production:

import { useEffect } from "react";
import { usePwa } from "@pwa-platform/react";

export function PwaActions() {
  const pwa = usePwa();

  useEffect(() => {
    if (import.meta.env.PROD) void pwa.register();
  }, [pwa.register]);

  return (
    <>
      {pwa.state.installEligible && (
        <button onClick={() => void pwa.promptInstall()}>安装应用</button>
      )}
      {pwa.state.updateWaiting && (
        <button onClick={() => void pwa.applyUpdate()}>更新应用</button>
      )}
    </>
  );
}

usePwa() returns registered, installEligible, installed and updateWaiting in state, plus register(), promptInstall(), checkForUpdate(), applyUpdate() and logout(). It throws outside a provider. Server rendering receives the initial all-false state; methods reject until called after hydration.

Optional update notice

import { PwaUpdateNotice } from "@pwa-platform/react/ui";
import "@pwa-platform/react/update-notice.css";

export function App() {
  return (
    <>
      <YourRoutes />
      <PwaUpdateNotice
        position="bottom-right"
        messages={{ readyTitle: "发现新版本", update: "立即更新", later: "稍后" }}
        colors={{ primaryButtonBackground: "#006e52", primaryButtonText: "#fff" }}
        reloadPage={() => location.reload()}
      />
    </>
  );
}

The notice is opt-in and non-modal. Positions are bottom-right, bottom-center, top-right and top-center. locale selects the built-in copy ("zh-CN", the default, or "en"); messages overrides individual keys on top of it; colors controls surface, text, muted text, border and primary button colors. CSS variables prefixed with --pwa-update- provide deeper theming. reloadPage runs only after worker takeover and an explicit click, allowing the host to protect unsaved work.

Lifecycle boundaries

  • Do not pass both client and updateCheck; an injected facade is already configured and the provider throws.
  • The provider creates/disposes the facade in an effect and remains safe under React Strict Mode.
  • applyUpdate() changes the controlling worker but never reloads the page unless the host or notice does it.
  • logout() returns the cleanup result but does not reset the binding's registered snapshot. Recreate/reload the provider if its UI must reflect an unregistered worker immediately.
  • The binding intentionally does not expose raw event subscription. Use @pwa-platform/client-runtime directly only when lifecycle telemetry such as served-from-cache is required.

See the React quick start and update prompt guide.