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

@dvirus-js/react

v0.0.24

Published

Downloads

1,734

Readme

@dvirus-js/react

Lightweight React utilities for class composition, data attributes, signal-style state, and context/service patterns.

Install

npm install @dvirus-js/react react

What This Package Includes

  • cx: tiny className composition helper.
  • toDataAttributes: converts plain objects to data-* props.
  • signals: function-style state primitives powered by React hooks.
  • context: context factories and provider registry helpers.

Exports

import { cx, toDataAttributes, useSignalState, useComputed, useWritableComputed, useResource, createBaseContext, createBaseContextSignal, createContextService, createContextRegistry } from '@dvirus-js/react';

Quick Start

import * as React from 'react';
import { cx, toDataAttributes, useSignalState, useComputed } from '@dvirus-js/react';

export function CounterCard() {
  const count = useSignalState(0);
  const doubled = useComputed(() => count() * 2, [count()]);

  return (
    <div className={cx('card', { 'card--hot': count() > 5 })} {...toDataAttributes({ count: count(), doubled: doubled() })}>
      <p>Count: {count()}</p>
      <p>Doubled: {doubled()}</p>
      <button onClick={() => count.update((n) => n + 1)}>Increment</button>
    </div>
  );
}

API Overview

cx(...values)

Composes class names from strings and conditional maps.

cx('btn', { 'btn-primary': true, disabled: false }, null);
// => "btn btn-primary"

Accepted values:

  • string
  • false | null | undefined (ignored)
  • Record<string, boolean | null | undefined>

toDataAttributes(source)

Converts object entries to data-* string attributes. null and undefined are omitted.

toDataAttributes({ state: 'active', index: 2, hidden: false, skip: undefined });
// => { 'data-state': 'active', 'data-index': '2', 'data-hidden': 'false' }

Signals

useSignalState(initial)

React state exposed as a writable signal:

  • signal() reads the current value
  • signal.set(next) replaces value
  • signal.update(fn) updates from previous value
  • signal.asReadOnly() hides mutation methods
const count = useSignalState(0);
count.set(10);
count.update((n) => n + 1);

useComputed(compute, deps)

Creates a read-only computed signal that recalculates when dependencies change.

const total = useComputed(() => items().reduce((a, b) => a + b.price, 0), [items()]);

useWritableComputed(compute, deps)

Like useComputed, but mutable (set and update are available).

useResource({ loader, deps?, defaultValue? })

Async resource helper exposing signal-backed request state.

Returned shape:

  • value: WritableSignal<T | undefined>
  • isLoading: Signal<boolean>
  • error: Signal<E | undefined>
  • reload(): reruns loader
const users = useResource({
  loader: () => fetch('/api/users').then((r) => r.json() as Promise<User[]>),
  deps: [teamId],
  defaultValue: [],
});

Context Utilities

createBaseContext(name, { factory })

Creates a context backed by React useState with:

  • Provider
  • useContext() returning [state, setState]
  • ValueRenderer renderer helper
const CounterContext = createBaseContext('CounterContext', {
  factory: () => 0,
});

function CountView() {
  const [count, setCount] = CounterContext.useContext();
  return <button onClick={() => setCount((n) => n + 1)}>{count}</button>;
}

createBaseContextSignal(name, { factory })

Creates a context backed by a writable signal with:

  • Provider
  • useContext() returning WritableSignal<T>
  • ValueRenderer renderer helper

createContextService(name, factory)

Creates a service-style context with a typed use() API:

  • use() throws if called outside provider
  • use({ optional: true }) returns undefined outside provider
const AuthService = createContextService('AuthService', () => {
  const user = useSignalState<{ id: string; name: string } | null>(null);
  return {
    user,
    login: (name: string) => user.set({ id: crypto.randomUUID(), name }),
    logout: () => user.set(null),
  };
});

createContextRegistry(providers)

Composes multiple providers into one.

Order rule:

  • first provider = outermost wrapper
  • last provider = innermost wrapper
const AppRegistry = createContextRegistry([AuthService, ThemeService]);

export function AppProviders({ children }: React.PropsWithChildren) {
  return <AppRegistry.Provider>{children}</AppRegistry.Provider>;
}

Notes

  • Peer dependency: react >= 18
  • Package type: ESM ("type": "module")

License

MIT