Skip to content

Zignal-React/zignal-core

Repository files navigation

@zignal/core

npm version MIT License bundle size npm downloads

Minimal, type-safe signal store for React (no persistence, no dependencies).

Install

npm install @zignal/core
# or
yarn add @zignal/core
# or
pnpm add @zignal/core

Usage

import { createZignal } from '@zignal/core';

const useCounter = createZignal(0);

function Counter() {
  const [count, setCount] = useCounter();
  return (
    <div>
      <button onClick={() => setCount(count - 1)}>-</button>
      <span>{count}</span>
      <button onClick={() => setCount(count + 1)}>+</button>
    </div>
  );
}

API

createZignal<T>(initial: T): () => [T, (v: T) => void]

Creates a React hook for a signal store. Returns a hook that gives you the value and a setter.

  • Type-safe: The value type is inferred from initial.
  • No dependencies: Only React is required.

MIT License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published