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

@typewirets/react

v0.1.0

Published

React adapter for TypeWire dependency injection

Readme

TypeWire React

React integration for TypeWireTS - seamlessly integrate TypeWire dependency injection with React components.

Installation

npm install @typewirets/react @typewirets/core

Quick Start

The most effective pattern for using TypeWire with React is with an async main function:

import { TypeWireContainer, typeWireGroupOf } from "@typewirets/core";
import { ResolutionContextProvider } from "@typewirets/react";
import ReactDOM from "react-dom/client";
import { ApiWire } from "./wires/api.wire";
import { UserStoreWire } from "./wires/user-store.wire";
import { App } from "./App";

async function main() {
  // Create the container
  const container = new TypeWireContainer();
  
  // Group all your TypeWires
  const wireGroup = typeWireGroupOf([
    ApiWire,
    UserStoreWire,
    // Add all your application wires here
  ]);

  // Apply all wires to the container at once
  await wireGroup.apply(container);
  
  // Render your React app with the container
  const rootEl = document.getElementById("root");
  const root = ReactDOM.createRoot(rootEl);
  root.render(<App container={container} />);
}

// Start your application
main().catch(console.error);

Then in your App component:

import { ResolutionContextProvider } from "@typewirets/react";
import type { ResolutionContext } from "@typewirets/core";
import { Suspense } from "react";

export function App({ container }: { container: ResolutionContext }) {
  return (
    <ResolutionContextProvider resolutionContext={container}>
      <Suspense fallback={<div>Loading application...</div>}>
        <YourComponents />
      </Suspense>
    </ResolutionContextProvider>
  );
}

Defining TypeWires for React

When defining TypeWires for React, use the createWith pattern for better dependency management:

// api.wire.ts
import { typeWireOf } from "@typewirets/core";

export const ApiWire = typeWireOf({
  token: "Api",
  createWith() {
    return {
      async fetchUsers() {
        const response = await fetch("/api/users");
        return response.json();
      },
      async updateUser(id: string, data: any) {
        // Implementation
      }
    };
  },
});

// user-store.wire.ts
import { typeWireOf } from "@typewirets/core";
import { create } from "zustand";
import { ApiWire } from "./api.wire";

export const UserStoreWire = typeWireOf({
  token: "UserStore",
  imports: {
    api: ApiWire,
  },
  createWith({ api }) {
    return create((set) => ({
      users: [],
      loading: false,
      error: null,
      
      fetchUsers: async () => {
        set({ loading: true });
        try {
          const users = await api.fetchUsers();
          set({ users, loading: false });
        } catch (error) {
          set({ error, loading: false });
        }
      },
      
      updateUser: async (id: string, data: any) => {
        // Implementation
      }
    }));
  },
});

Using TypeWires in Components

Access your TypeWires in React components with the useTypeWire hook:

import { useTypeWire } from "@typewirets/react";
import { UserStoreWire } from "./wires/user-store.wire";
import { useEffect } from "react";

export function UserList() {
  const userStore = useTypeWire(UserStoreWire);
  const { users, loading, error, fetchUsers } = userStore;
  
  useEffect(() => {
    fetchUsers();
  }, [fetchUsers]);
  
  if (loading) return <div>Loading users...</div>;
  if (error) return <div>Error: {error.message}</div>;
  
  return (
    <ul>
      {users.map(user => (
        <li key={user.id}>{user.name}</li>
      ))}
    </ul>
  );
}

Handling Async TypeWires

When using TypeWires with async initialization, React Suspense handles the loading state:

// Component that depends on an async TypeWire
function UserDashboard() {
  const userStore = useTypeWire(UserStoreWire);
  
  // If UserStoreWire has async initialization,
  // React Suspense will catch the promise and show the fallback
  
  return <UserList />;
}

// In your parent component
function App({ container }) {
  return (
    <ResolutionContextProvider resolutionContext={container}>
      <Suspense fallback={<div>Loading dashboard...</div>}>
        <UserDashboard />
      </Suspense>
    </ResolutionContextProvider>
  );
}

Core Components

  • ResolutionContextProvider: Provides TypeWire container to React components
  • useTypeWire: Hook to access TypeWire instances in components
  • useContainer: Direct access to the ResolutionContext (advanced use cases)

Best Practices

  1. Initialize TypeWires in a main function:

    • Group your TypeWires with typeWireGroupOf
    • Apply them all at once before rendering
  2. Use state management libraries with TypeWire:

    • Zustand, Redux, or MobX work well with TypeWire
    • Inject TypeWires as dependencies using imports and createWith
  3. Structure your application by features:

    • Group related TypeWires by feature
    • Co-locate TypeWires with their React components
  4. Ensure proper cleanup:

    • If your TypeWires need cleanup, register cleanup handlers
    • Use React's useEffect for component-level cleanup

License

MIT