Skip to content

fictjs/hooks

Repository files navigation

@fictjs/hooks

Node CI npm license

Official hooks package for Fict.

@fictjs/hooks provides official, production-ready hooks built for Fict signal/lifecycle semantics.

Highlights

  • 39 official hooks across lifecycle, event, timing, state, browser, storage, observer, async and clipboard
  • SSR-safe browser hooks with injectable globals (window, document, navigator) for non-browser/test environments
  • Root-only public entry (@fictjs/hooks) with ESM tree shaking support
  • Published Fict package metadata (dist/index.fict.meta.json) for cross-package hook return reactivity
  • Strong type and coverage gates (lint, typecheck, test:types, test:coverage, build, verify:metadata, test:attw)

Install

For application usage:

npm add @fictjs/hooks @fictjs/runtime
# or
yarn add @fictjs/hooks @fictjs/runtime
# or
pnpm add @fictjs/hooks @fictjs/runtime

Requirements

  • Runtime consumers: Node.js >= 18
  • Repository development/build/test: Node.js ^22.18.0 || >=24.11.0 (the supported range of the build toolchain)
  • Release publishing: Node.js 24.11 or newer
  • Peer dependency: @fictjs/runtime@^0.26.0

Quick Start

import { useCounter, useMount } from '@fictjs/hooks';

export function CounterExample() {
  const { count, inc, dec, reset } = useCounter(0);

  useMount(() => {
    inc();
  });

  return { count, inc, dec, reset };
}

In plain TypeScript/JavaScript usage (without Fict compile transforms), read reactive values via accessors, for example count().

Import Policy

  • Only import from @fictjs/hooks; deep imports are unsupported
  • Tree shaking is supported through ESM exports and "sideEffects": false

Fict Metadata

pnpm build emits:

  • dist/index.fict.meta.json
  • ESM/CJS runtime files
  • .d.ts and .d.cts type declarations

package.json#fict.metadata points at the generated metadata file so Fict 0.26.0 consumers can recover hook return reactivity from the published npm package.

Run pnpm verify:metadata after pnpm build to verify the generated metadata and the npm tarball contents.

Runtime Semantics

  • Hooks follow Fict top-level hook rules (useX in component/hook top-level scope)
  • Effects/listeners/timers are auto-cleaned on root dispose
  • Browser hooks are SSR-safe and provide unsupported fallbacks
  • Browser globals can be injected with options like window, document, or navigator when needed

Hook Docs

All hook docs are versioned with each release under docs/hooks.

Demo Website

Run interactive hook demos:

pnpm demo:dev

Build static demo site:

pnpm demo:build

Quality Gates

Before publish, these checks must pass:

  1. pnpm audit:dev
  2. pnpm lint
  3. pnpm format:check
  4. pnpm typecheck
  5. pnpm test:types
  6. pnpm test:types:ts53
  7. pnpm test:coverage
  8. pnpm build
  9. pnpm verify:size
  10. pnpm lint:dist
  11. pnpm verify:metadata
  12. pnpm test:attw

prepublishOnly already enforces this pipeline.

License

MIT

About

Official hooks package for Fict

Resources

License

Stars

3 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors