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

@quanta-lib/q-state

v1.1.7

Published

A lightweight React state management library using `useSyncExternalStore` with optional localStorage caching and value transformation.

Readme

Q-State

A lightweight React state management engine using useSyncExternalStore with optional localStorage caching and value transformation.

Small issue (FIXED)

Hey i have an isssue, when you use nextjs with this library, just copy the engine code in the q-state file because this library had hydration issue, after you copy it, use it inside your src file, so this library can work well in nextjs, im sorry for that... (BUG FIXED, Q-STATE COMPATIBLE WITH NEXTJS NOW!)

Github link

Here my open source github link, lets colaborate and grow together! https://github.com/ammaar-engineer/Q-State

Installation

npm install @quanta-lib/q-state
## Features

- **Type-safe state management** - Full TypeScript support with generic types
- **useSyncExternalStore** - Uses React's built-in concurrent-safe subscription mechanism
- **Value transformation** - Transform values during updates with custom transformer functions
- **LocalStorage caching** - Persist state to localStorage with optional caching
- **Lightweight** - Minimal dependencies, no context providers needed

## Usage

### Basic Usage

```typescript
import { Q_StateEngine } from "@q-state/core"

const qstate = new Q_StateEngine({
  count: 0,
  name: 'Amarix'
})

export function App() {
  const [count] = qstate.useQuantaState('count')
  const [name] = qstate.useQuantaState('name')

  return (
    <>
      <h1>Counter App</h1>
      <p>Name: {name}</p>
      <p>Count: {count}</p>
      <button onClick={() => qstate.updateValue('count', (prev) => prev + 1)}>
        Increment
      </button>
    </>
  )
}

With Value Transformer

Transform values automatically when updating state:

const qstate = new Q_StateEngine({
  name: 'Amarix'
}, {
  // Transformer function runs after updateValue
  name: (raw) => {
    console.log(raw) // Logs the new value
    return raw.toUpperCase() // Transform to uppercase
  }
})

// When updating name, the transformer will be applied
qstate.updateValue('name', () => 'hello') // Stores 'HELLO'

With LocalStorage Caching

Enable caching to persist state across page reloads:

const qstate = new Q_StateEngine({
  count: 0,
  name: 'Amarix'
}, {
  name: (raw) => console.log(raw)
}, {
  cache: true // Enable localStorage caching
})

Nested Updates

You can update multiple state values in a single update function:

<button onClick={() => qstate.updateValue('name', () => {
  qstate.updateValue('count', () => 5) // Nested update
  return 'helo :3'
})}>
  Update Name
</button>

API

Constructor

new Q_StateEngine<T, O>(state: T, transformer?: O, option?: OptionRecord)
  • state (T): Initial state object with type safety
  • transformer (O, optional): Record of transformer functions for specific keys
  • option (OptionRecord, optional): Configuration options
    • cache: Enable localStorage caching (default: false)

Methods

updateValue(key, func)

Updates a state value using an updater function.

qstate.updateValue('count', (prev) => prev + 1)
  • key: The state key to update
  • func: Updater function that receives the current value and returns the new value

useQuantaState(key)

React hook for subscribing to state changes.

const [value] = qstate.useQuantaState('key')

Returns a tuple with the current value. The component re-renders when the specified key changes.

TypeScript

The library provides full type safety:

interface AppState {
  count: number
  name: string
  items: string[]
}

const qstate = new Q_StateEngine<AppState>({
  count: 0,
  name: '',
  items: []
})

// Type-safe updates
qstate.updateValue('count', (prev) => prev + 1) // ✓
qstate.updateValue('name', () => 'Hello')      // ✓
qstate.updateValue('items', (prev) => [...prev, 'new']) // ✓

How It Works

  1. State Storage: State is stored in a private object within the Q_StateEngine instance
  2. Subscription: Uses React's useSyncExternalStore for concurrent-safe subscriptions
  3. Updates: When updateValue is called, it:
    • Executes the updater function with the current value
    • Runs the transformer function (if defined)
    • Updates the internal state
    • Persists to localStorage (if caching enabled)
    • Notifies all subscribers
  4. Caching: On initial render, checks localStorage for cached values and hydrates state

License

MIT