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

serla-js-react

v0.1.1

Published

Official React bindings for the Serla analytics JS SDK

Readme

serla-js-react

Official React bindings for serla-js — the JavaScript SDK for Serla analytics.

  • Tiny: a provider, four hooks, one declarative component
  • ESM + CJS, TypeScript types included
  • Wraps the core serla-js singleton — no duplicate state in your React tree
  • Works in Next.js App Router, Remix, Vite, CRA, anything React 18+

Install

npm install serla-js serla-js-react

Both packages are required — serla-js is a peer dependency so a single copy of the SDK lives in your app.

Quick start (Next.js App Router)

// app/providers.tsx
'use client';

import { SerlaProvider } from 'serla-js-react';

export function Providers({ children }: { children: React.ReactNode }) {
  return (
    <SerlaProvider
      config={{
        apiKey: process.env.NEXT_PUBLIC_SERLA_API_KEY!,
        autoPageviews: true,
      }}
    >
      {children}
    </SerlaProvider>
  );
}
// app/layout.tsx
import { Providers } from './providers';

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

API

<SerlaProvider config={...}>

Calls Serla.init(config) once on mount and Serla.shutdown() on unmount. The config prop is read only on mount — changing it later is intentionally ignored, since the core SDK does not support reconfiguration.

<SerlaProvider config={{ apiKey: 'sk_live_...', autoPageviews: true }}>
  <App />
</SerlaProvider>

In React StrictMode (dev) effects run twice, so init -> shutdown -> init happens — this is harmless and only affects development.

useSerla()

Returns the Serla singleton. Equivalent to import { Serla } from 'serla-js', but warns once in development if no <SerlaProvider> is mounted.

function MyButton() {
  const serla = useSerla();
  return <button onClick={() => serla.track('cta_clicked', { variant: 'hero' })}>Click</button>;
}

useTrack(name)

Returns a stable function bound to an event name. The returned function takes optional per-call properties.

function MyButton() {
  const trackClick = useTrack('cta_clicked');
  return <button onClick={() => trackClick({ variant: 'hero' })}>Click</button>;
}

The function identity is stable as long as name doesn't change — safe to pass into memoized children or effect dependency arrays.

useIdentify(distinctId, properties?)

Effects-driven identify(). Pass a distinct ID (or null when logged out) and optional properties. Only re-fires when the inputs actually change, so passing fresh object literals from a parent's render is fine.

function App({ user }) {
  useIdentify(user?.id ?? null, user ? { email: user.email, plan: user.plan } : undefined);
  return <Routes />;
}
  • Transitioning distinctId from a string to null calls Serla.reset().
  • On unmount, if you ever identified, the hook calls Serla.reset().

useSuperProperties(properties | null)

Declarative wrapper around Serla.setProperties() / Serla.unsetProperties(). The hook tracks the keys it set and removes them when you stop passing them (or pass null).

function App({ user }) {
  useSuperProperties(user ? { plan: user.plan, appVersion: '4.2.1' } : null);
  // ...
}
  • Pass null to clear the keys this hook owned.
  • Unrelated super properties set via Serla.setProperties() elsewhere are not touched.

<Track event="..." properties={...} />

Declarative one-shot tracker that fires the event exactly once on mount. Useful for view-tracking modals and overlays where the mount itself is the signal:

{showUpgradeModal && (
  <Modal>
    <Track event="upgrade_modal_viewed" properties={{ plan: 'pro' }} />
    <h1>Upgrade to Pro</h1>
  </Modal>
)}

Re-exported types

import type { SerlaConfig, EventProperties } from 'serla-js-react';
import { Serla } from 'serla-js-react'; // same singleton as serla-js

License

MIT