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 🙏

© 2024 – Pkg Stats / Ryan Hefner

statera

v1.0.9

Published

A lightweight state management library for React

Downloads

4

Readme

Statera

Statera is a lightweight, easy-to-use state management library for React applications. It provides a simple and intuitive API for managing and sharing state across components without the need for complex setups or provider components.

npm npm bundle size npm

Features

  • 🚀 Lightweight (less than 1KB gzipped)
  • 🔧 Zero configuration
  • 🧠 Intuitive API similar to React's useState
  • 🔄 Efficient updates with React's useSyncExternalStore
  • 🌳 No need for provider components
  • 📦 TypeScript support out of the box
  • 🖥️ Server-Side Rendering (SSR) support

Installation

npm install statera
# or
yarn add statera
# or
pnpm add statera

Usage

Here's a quick example of how to use Statera:

import React from "react";
import { statera } from "statera";

// Create a shared state
const useCounter = statera(0);

function Counter() {
  const [count, setCount] = useCounter();

  return (
    <div>
      <p>Count: {count}</p>
      <button onClick={() => setCount(count + 1)}>Increment</button>
      <button onClick={() => setCount((prev) => prev - 1)}>Decrement</button>
    </div>
  );
}

function App() {
  return (
    <div>
      <Counter />
      <Counter />
    </div>
  );
}

In this example, both Counter components share the same state. Updating the count in one component will update it in the other as well.

API

statera

const useMyState = statera(initialState);

Creates a new shared state with the given initial value and returns a custom hook.

Using the state

const [state, setState] = useMyState();

Returns a tuple containing the current state and a setter function, similar to React's useState.

The setter function can be used in two ways:

  1. Passing a new value directly:

    setState(newValue);
  2. Passing a function that receives the previous state:

    setState(prevState => /* compute and return new state */);

Server-Side Rendering (SSR)

Statera supports Server-Side Rendering out of the box. It works seamlessly with frameworks like Next.js without any additional configuration.

Why Statera?

  • Simplicity: Statera provides a familiar API that React developers already know, making it easy to learn and use.
  • Performance: Built on top of React's useSyncExternalStore, Statera ensures efficient updates and renders.
  • Flexibility: Can be used for both simple and complex state management scenarios.
  • Lightweight: Adds minimal overhead to your bundle size.
  • SSR Support: Works seamlessly in server-side rendered applications.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.


Created by Sangeet Banerjee