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

supastate

v0.3.1

Published

A lightweight, easy-to-use React hook for managing global state without the complexity of external state management libraries

Downloads

3

Readme

supastate

supastate

A lightweight, easy-to-use React hook for managing global state without the complexity of external state management libraries. Designed to be minimal yet powerful, supastate enables developers to efficiently manage serializable state with operations that include setting, updating, and effectively reacting to state changes. It's ideal for small to medium-sized applications that require flexible global state management.

Features

  • Custom Hook Factory: Generate tailor-made React hooks (useSupastate) for efficient state management in applications.
  • Serializable State Only: Supports states that are serializable, enhancing compatibility with JSON serialization for features like state persistence.
  • In-Memory State: Maintains state in memory for fast access and updates, with each hook managing its own state.
  • Flexible State Updates:
    • Direct Set: Allows direct replacement of the current state.
    • Updater Function: Enables complex state transformations through a functional updater.
  • Automatic Update Propagation: Uses a listener pattern for automatic re-rendering of components on state updates.
  • Clean-Up Mechanism: Automatically removes listeners on component unmount, preventing memory leaks.
  • Minimal API: Simplifies state management with an intuitive and minimalistic API, reducing boilerplate.
  • Immutable Updates: Promotes state immutability for reliable and predictable updates.
  • Easy Integration: Designed for seamless integration into existing React projects with minimal setup.

Leverage the power of React's ecosystem with this lightweight, intuitive state management solution.

Installation

npm install supastate

Or using yarn:

yarn add supastate

Usage

Here's a quick example to get you started:

import React from "react";
import { createSupastate } from "supastate";

// Using createSupastate to create a global state for a user profile
const useUserProfile = createSupastate({ name: "John Doe", age: 30 }); // Initial state is a profile object

// UserProfile Component: Displays the user's name and age
function UserProfile() {
  const { state: userProfile } = useUserProfile();

  return (
    <div>
      <p>Name: {userProfile.name}</p>
      <p>Age: {userProfile.age}</p>
    </div>
  );
}

// UpdateName Component: Has an input field to update the user's name
function UpdateName() {
  const { update } = useUserProfile();

  return (
    <input
      type="text"
      placeholder="Enter new name"
      onChange={(e) =>
        update((currentProfile) => ({
          ...currentProfile,
          name: e.target.value,
        }))
      }
    />
  );
}

// IncrementAge Component: Has a button to increment the user's age
function IncrementAge() {
  const { update } = useUserProfile();

  return (
    <button
      onClick={() =>
        update((currentProfile) => ({
          ...currentProfile,
          age: currentProfile.age + 1,
        }))
      }
    >
      Increment Age
    </button>
  );
}

// Main application that uses the UserProfile, UpdateName, and IncrementAge components
function App() {
  return (
    <div>
      <UserProfile />
      <UpdateName />
      <IncrementAge />
    </div>
  );
}

API Reference

  • set(payload: T): Sets the new state.
  • update(updater: (state: T) => T): Updates the state based on the previous state.
  • createSupastate(initialState: T): Creates a new instance of the supastate hook with the defined initial state.

Support

If you need help or have any questions, please open an issue in the GitHub repository.

Thank you for using supastate!


Roadmap

1. Functional Enhancements

  • Async Actions Support: Makes handling asynchronous operations easier.
  • Middlewares: Enables adding extra logic for actions, useful for activities like logging and persistence.
  • State Persistence: Integrates methods to maintain state between sessions using localStorage or local databases.

2. Performance Optimization

  • Memoization: Utilizes memoization to improve efficiency.
  • Updates Batching: Minimizes re-renders by grouping state updates.

3. Testing and Security

  • Testing: Implements unit and integration tests to ensure reliability.
  • Data Sanitization: Protects against security risks by sanitizing user inputs.

4. Compatibility and Usability

  • Additional Hooks: Adds hooks to ease common use cases.
  • Concurrent Mode and TypeScript Support: Ensures compatibility with the latest React features and enhances experience with TypeScript support.

5. Community

  • Documentation and Repository: Provides detailed documentation and manages an accessible repository to encourage collaboration.
  • User Feedback: Adjusts the roadmap based on user suggestions and needs.
  • Continuous Update: Stays updated with React advancements.