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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@gadgetinc/client-hooks

v0.1.5

Published

This package contains shared implementations of core hooks used in React/Preact libraries for Gadget applications. `@gadgetinc/client-hooks` provides framework-agnostic hook implementations that are consumed by framework-specific packages like `@gadgetinc

Readme

Client Hooks

This package contains shared implementations of core hooks used in React/Preact libraries for Gadget applications. @gadgetinc/client-hooks provides framework-agnostic hook implementations that are consumed by framework-specific packages like @gadgetinc/react and @gadgetinc/preact.

Note that developers shouldn't need to use this package directly and should instead use their generated client plus framework-specific binding packages like @gadgetinc/react.

Overview

@gadgetinc/client-hooks is designed with a runtime adapter pattern that allows the same hook logic to work across different UI frameworks (React, Preact, etc.). The package exports:

  • Core hook implementations for querying and mutating Gadget APIs
  • A RuntimeAdapter interface that framework-specific packages implement
  • A registration system via registerClientHooks to bind hooks to a specific framework

Architecture

The library uses an adapter pattern to remain framework-agnostic:

interface RuntimeAdapter {
  GadgetApiContext: Context<GadgetApiContext>;
  framework: FrameworkBindings; // useState, useEffect, useMemo, etc.
  urql: UrqlBindings; // useQuery, useMutation
}

Framework-specific packages (like @gadgetinc/react) provide an adapter implementation that maps to their framework's primitives, then call registerClientHooks to initialize the hooks with that adapter.

Available Hooks

Query Hooks

  • useFindOne - Fetch a single record by ID
  • useMaybeFindOne - Fetch a single record by ID, returning null if not found
  • useFindMany - Fetch a page of records with filtering, sorting, and pagination
  • useFindFirst - Fetch the first record matching criteria
  • useMaybeFindFirst - Fetch the first record matching criteria, returning null if not found
  • useFindBy - Fetch a record by a unique field value
  • useGet - Fetch a singleton record (e.g., current session)
  • useView - Fetch records from a backend view

Mutation Hooks

  • useAction - Run an action on a model record (create, update, delete, etc.)
  • useBulkAction - Run an action on multiple records at once
  • useGlobalAction - Run a global action

Utility Hooks

  • useFetch - Make HTTP requests to backend routes
  • useEnqueue - Enqueue background actions
  • useQuery - Low-level GraphQL query hook
  • useMutation - Low-level GraphQL mutation hook
  • useApi - Access the Gadget API client instance
  • useConnection - Access the Gadget connection instance
  • useCoreImplementation - Access the core implementation details

How Framework Packages Use This

Framework-specific packages like @gadgetinc/react follow this pattern:

  1. Import hooks and utilities from @gadgetinc/client-hooks
  2. Create a RuntimeAdapter implementation for their framework
  3. Create a Provider component that calls registerClientHooks
  4. Re-export the hooks for end users

Example:

import { registerClientHooks, useAction, useFindMany } from "@gadgetinc/client-hooks";
import { useContext, useMemo /* ... */ } from "react";
import { useQuery, useMutation } from "urql";

// Create adapter for React
const adapter: RuntimeAdapter = {
  framework: { useContext, useMemo /* ... */ },
  urql: { useQuery, useMutation, Provider },
  GadgetApiContext: createContext(/* ... */),
};

// Provider component initializes the hooks
export const Provider = ({ api, children }) => {
  const { gadgetClient, urqlClient } = registerClientHooks(api, adapter);
  // ... render provider with context
};

// Re-export hooks for users
export { useAction, useFindMany /* ... */ };

For Gadget Developers

This package is designed to reduce code duplication between React and Preact (and potentially other frameworks). When adding new functionality:

  1. Implement the hook logic once in @gadgetinc/client-hooks
  2. Use the RuntimeAdapter for any framework-specific calls
  3. Export the hook from the package
  4. Re-export from framework packages like @gadgetinc/react

The hook registration system uses a stub pattern where hooks throw helpful errors if called outside a proper Provider context, then get replaced with real implementations once registerClientHooks is called.