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

synstate-react-hooks

v1.0.2

Published

Type-safe State Management Library for TypeScript/JavaScript

Downloads

404

Readme

SynState React hooks

synstate-react-hooks re-exports all exports from synstate except for createState, createReducer, and createBooleanState, and exports modified versions of those creation functions.

The first element of the array returned by the createState<T> function provided by synstate-preact-hooks is changed from InitializedObservable<T> to a React hook () => T, and the InitializedObservable<T> has been moved to the state property in the object at index 2.

Installation

npm add synstate-react-hooks

Or with other package managers:

# Yarn
yarn add synstate-react-hooks

# pnpm
pnpm add synstate-react-hooks

Quick Start

Simple State Management

import type * as React from 'react';
import { createState } from 'synstate-react-hooks';

// Global state (outside component)
const [useUserState, setUserState] = createState({
    name: '',
    email: '',
});

const UserProfile = (): React.JSX.Element => {
    const user = useUserState();

    return (
        <div>
            <p>{`Name: ${user.name}`}</p>
            <button
                onClick={() => {
                    setUserState({
                        name: 'Alice',
                        email: '[email protected]',
                    });
                }}
            >
                {'Set User'}
            </button>
        </div>
    );
};

With resetState, updateState, state APIs:

import type * as React from 'react';
import { createState } from 'synstate-react-hooks';

// Global state (outside component)
const [
    useUserState,
    setUserState,
    {
        resetState: resetUserState,
        updateState: updateUserState,
        state: userState,
    },
] = createState({
    name: '',
    email: '',
});

userState.subscribe((u) => {
    console.log('User is updated:', u);
});

const UserProfile = (): React.JSX.Element => {
    const user = useUserState();

    return (
        <div>
            <p>{`Name: ${user.name}`}</p>
            <button
                onClick={() => {
                    setUserState({
                        name: 'Alice',
                        email: '[email protected]',
                    });
                }}
            >
                {'Set User'}
            </button>
            <button
                onClick={() => {
                    updateUserState((prev) => ({
                        name: prev.name,
                        email: '',
                    }));
                }}
            >
                {'Reset email'}
            </button>
            <button onClick={resetUserState}>{'Reset'}</button>
        </div>
    );
};

Subscribing to Observables: useObservableValue

Use useObservableValue to read any Observable — including derived ones produced by pipe / combine — from a React component. It is implemented on top of useSyncExternalStore, so the component re-renders whenever the source emits.

Overloads

| Signature | Return type | When to use | | ------------------------------------------------------------------- | ---------------- | ----------------------------------------------------------------------------------------------------------------------------- | | useObservableValue<A>(obs: InitializedObservable<A>) | A | The observable always has a current value (e.g. came from createState, or a pipe chain that preserves the initial value). | | useObservableValue<A>(obs: Observable<A>) | A \| undefined | The observable may not have emitted yet (no initial value). | | useObservableValue<A, B = A>(obs: Observable<A>, initialValue: B) | A \| B | Provide a fallback used while the observable has no value. Implemented via Optional.unwrapOr. |

Example

import type * as React from 'react';
import { map, type Observable } from 'synstate';
import { createState, useObservableValue } from 'synstate-react-hooks';

const [useCount, setCount, { state: count$ }] = createState(0);

// Derived InitializedObservable — no fallback needed.
const doubled$ = count$.pipe(map((n) => n * 2));

// Imagine an Observable<string> that has no initial value
// (e.g. one waiting on an async source).
declare const userName$: Observable<string>;

const Profile = (): React.JSX.Element => {
    const doubled = useObservableValue(doubled$); // number

    const userName = useObservableValue(userName$, 'Guest'); // string

    return (
        <div>
            <p>{`Doubled count: ${doubled}`}</p>
            <p>{`Hello, ${userName}`}</p>
        </div>
    );
};