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

oustate

v1.1.0

Published

πŸ‘€ Another React state management library

Downloads

52

Readme

Oustate πŸŒ€

Welcome to Oustate – your new best friend for managing state in React applications! Making state management a breeze, focused on simplicity and scalability for real-world scenarios.

Build Code quality check Build Size

πŸš€ Features

  • Easy State Creation: Kickstart your state management with simple and intuitive APIs.
  • Selectors & Merges: Grab exactly what you need from your state and combine multiple states seamlessly.
  • Deep Nesting Support: Handle complex state structures without breaking a sweat.
  • Optimized Rendering: Prevent unnecessary re-renders with smart equality checks.
  • Concurrency Handling: Stay cool under pressure with robust concurrency support.
  • TypeScript Ready: Fully typed for maximum developer sanity.

πŸ“¦ Installation

bun add oustate
# or
yarn add oustate
# or
npm install oustate

πŸ“ Quick Start

import { create } from 'oustate'

const useCounter = create(0)

function Counter() {
  const counter = useCounter()
  return <div onClick={() => useCounter.setState((prev) => prev + 1)}>{counter}</div>
}

Selecting parts of the state globally

import { create } from 'oustate'

const useUser = create({ name: 'John', age: 30 })

const useName = useUser.select((user) => user.name)
const useAge = useUser.select((user) => user.age)

function Counter() {
  const name = useName()
  return <div onClick={() => useUser.setState((prev) => ({ ...prev, name: 'Jane' }))}>{counter}</div>
}

Or lazy

import { create } from 'oustate';
// getter function, it'a lazy state initialization, loaded only when it's accessed
const useCounter = create(() => 0); 

function Counter() {
  const counter = useCounter();
  return (
    <div onClick={() => useCounter.setState((prev) => prev + 1)}>
      {counter}
    </div>
  );
}

Or merge two states

import { create } from 'oustate';
// getter function, it'a lazy state initialization, loaded only when it's accessed
const useName = create(() => 'John');
const useAge = create(() => 30);

const useUser = useName.merge(useAge, (name, age) => ({ name, age }));

function Counter() {
  const {name, age} = useUser();
  return (
    <div onClick={() => useName.setState((prev) => 'Jane')}>
      {counter}
    </div>
  );
}

Promise based state and lifecycle management working with React Suspense

This methods are useful for handling async data fetching and lazy loading via React Suspense.

Immediate Promise resolution

import { create } from 'oustate';
 // state will try to resolve the promise immediately, can hit the suspense boundary
const counterState = create(Promise.resolve(0));

function Counter() {
  const counter = counterState();
  return (
    <div onClick={() => counterState.setState((prev) => prev + 1)}>
      {counter}
    </div>
  );
}

Lazy Promise resolution

import { create } from 'oustate';
// state will lazy resolve the promise on first access, this will hit the suspense boundary if the first access is from component and via `counterState.getState()` method
const counterState = create(() => Promise.resolve(0)); 

function Counter() {
  const counter = counterState();
  return (
    <div onClick={() => counterState.setState((prev) => prev + 1)}>
      {counter}
    </div>
  );
}

πŸ” API Reference

create

Creates a basic atom state.

function create<T>(defaultState: T, options?: StateOptions<T>): StateSetter<T>;

Example:

const userState = create({ name: 'John', age: 30 });

select

Selects a slice of an existing state directly or via a selector function.

// userState is ready to use as hook, so you can name it with `use` prefix
const userState = create({ name: 'John', age: 30 });
// Direct selection outside the component, is useful for accessing the slices of the state in multiple components
const userAgeState = userState.select((user) => user.age);

// Selection via selector in hook function
const userNameState = select(userState, (user) => user.name);
function select<T, S>(state: StateGetter<T>, selector: (value: T) => S, isEqual?: IsEqual<S>): StateGetter<S>;

Example:

const userAgeState = select(userState, (user) => user.age);

merge

Merges two states into a single state. But be careful about creating new references on each call, it can lead to maximum call stack exceeded error.

function merge<T1, T2, S>(
  state1: GetterState<T1>,
  state2: GetterState<T2>,
  selector: (value1: T1, value2: T2) => S,
  isEqual?: IsEqual<S>
): GetterState<S>

Access from outside the component

:warning: Avoid using this method for state management in React Server Components, especially in Next.js 13+. It may cause unexpected behavior or privacy concerns.

const userState = create({ name: 'John', age: 30 });
const user = userState.getState();

Slicing new references

:warning: Slicing data with new references can lead to maximum call stack exceeded error. It's recommended to not use new references for the state slices, if you need so, use shallow or other custom equality checks.

import { state, shallow } from 'oustate';
const userState = create({ name: 'John', age: 30 });
// this slice will create new reference object on each call
const useName = userState.select((user) => ({newUser: user.name }), shallow);

πŸ€– Contributing

Contributions are welcome! Please read the contributing guidelines before submitting a pull request.

πŸ§ͺ Testing

Oustate comes with a robust testing suite. Check out the state.test.tsx for examples on how to write your own tests.

πŸ“œ License

Oustate is MIT licensed.