
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
@gadgetinc/client-hooks
Advanced tools
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
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.
@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:
RuntimeAdapter interface that framework-specific packages implementregisterClientHooks to bind hooks to a specific frameworkThe 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.
useFindOne - Fetch a single record by IDuseMaybeFindOne - Fetch a single record by ID, returning null if not founduseFindMany - Fetch a page of records with filtering, sorting, and paginationuseFindFirst - Fetch the first record matching criteriauseMaybeFindFirst - Fetch the first record matching criteria, returning null if not founduseFindBy - Fetch a record by a unique field valueuseGet - Fetch a singleton record (e.g., current session)useView - Fetch records from a backend viewuseAction - Run an action on a model record (create, update, delete, etc.)useBulkAction - Run an action on multiple records at onceuseGlobalAction - Run a global actionuseFetch - Make HTTP requests to backend routesuseEnqueue - Enqueue background actionsuseQuery - Low-level GraphQL query hookuseMutation - Low-level GraphQL mutation hookuseApi - Access the Gadget API client instanceuseConnection - Access the Gadget connection instanceuseCoreImplementation - Access the core implementation detailsFramework-specific packages like @gadgetinc/react follow this pattern:
@gadgetinc/client-hooksRuntimeAdapter implementation for their frameworkProvider component that calls registerClientHooksExample:
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 /* ... */ };
This package is designed to reduce code duplication between React and Preact (and potentially other frameworks). When adding new functionality:
@gadgetinc/client-hooksRuntimeAdapter for any framework-specific calls@gadgetinc/reactThe 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.
FAQs
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
We found that @gadgetinc/client-hooks demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.