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

react-state-fully

v1.17.1

Published

Fully encapsulated state management for specific state types

Downloads

36

Readme

react-state-fully npm

Fully encapsulated state management for specific state types.

Installation

npm i react-state-fully

Introduction

React is a powerful, component-based, tool that streamlines the process of developing clean readable website code! And through the use of React Hooks, developers can easily add and create additional functionalities which aren't already in React! react-state-fully encapsulates the unnecessary details of setting and updating state away so you can make typical Javascript calls to your data types without having to worry about updating your state properly.

Getting Started

To get started, install react-state-fully in your project.

npm i react-state-fully

Abstractions

The name State-Fully is derived from the idea that we attempted to encapsulate common data-type methods so that they'd properly leverage React's state system.

Some React code comparisons:

{
    // Traditional method for concatting a string in React
    const [ value, setValue ] = useState("This is some text!");
    console.log(value);

    setValue(value + "Plus some more!");
}
{
    // State-Fully method for concatting a string in React
    const value = State.useString("This is some text!");
    console.log(value);

    value.concat('Plus some more!'); // Concat automatically handles state so you don't have to!
}
{
    // Traditional method for incrementing a number in React
    const [ value, setValue ] = useState(10);
    console.log(value);

    setValue(value + 1);
}
{
    // State-Fully method for incrementing a number in React
    const value = State.useNumber(10);
    console.log(value);

    value.increment();
}
{
    // Traditional method for adding/removing values from a Set in React
    const [ values, setValues ] = useState(new Set<string>());
    console.log(values);

    { // Add value
        const newSet = new Set<string>([...values, "some value"]);
        setValues(newSet);
    }

    { // Remove value
        const newSet = new Set<string>(values);
        newSet.delete("some other value");
        setValues(newSet);
    }
}
{
    // State-Fully method for adding/removing values from a Set in React
    const values = State.useSet();
    console.log(value);

    values.add("some value");
    values.remove("some other value");
}

Using State-Fully

To get started, install react-state-fully in your project.

npm i react-state-fully

From there, all of the encapsulated data types can be fetched via the State object. When you use one the contained hooks, it'll instantiate a new state for the specified datatype.

const array = State.useArray<string>();
const set = State.useSet<string>();
const map = State.useMap<string, any>();
const number = State.useNumber();
const string = State.useString();
const boolean = State.useBoolean();

Something you'll notice is that we only get back one variable instead of a state variable and a setter variable. Users from languages such as Java will be right at home here because reading and altering state can now all be done from the same variable. There's also a generic state type for if you have your own custom object that you want to be able to handle using .get() and .set() methods.

const object = State.useGeneric<MyObject>({}); // Initial value is required on useGeneric