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-signify

v1.5.4

Published

A JS library for predictable and maintainable global state management

Downloads

353

Readme

React Signify

image

Introduction

React Signify is a simple library that provides features for managing and updating global state efficiently. It is particularly useful in React applications for managing state and auto-syncing when their values change. Advantages of the library:

  • Lightweight library
  • Simple syntax
  • Supports effective re-render control

Project information

Installation

React Signify is available as a package on NPM for use with React applications:

# NPM
npm install react-signify

# Yarn
yarn add react-signify

Overview

Initialize

You can initialize Signify in any file, please refer to the following example

import { signify } from 'react-signify';

const sCount = signify(0);

Here we create a variable sCount with an initial value of 0.

Used in many places

The usage is simple with the export/import tool of the module. File Store.js (export Signify)

import { signify } from 'react-signify';

export const sCount = signify(0);

Component A (import Signify)

import { sCount } from './store';

export default function ComponentA() {
    const countValue = sCount.use();
    const handleUp = () => {
        sCount.set(pre => (pre.value += 1));
    };

    return (
        <div>
            <h1>{countValue}</h1>
            <button onClick={handleUp}>UP</button>
        </div>
    );
}

From here we can see the flexibility of Signify, simple declaration, usable everywhere.

Basic features

Display on the interface

We will use the html attribute to display the value as a string or number on the interface.

import { signify } from 'react-signify';

const sCount = signify(0);

export default function App() {
    return (
        <div>
            <h1>{sCount.html}</h1>
        </div>
    );
}

Update value

import { signify } from 'react-signify';

const sCount = signify(0);

export default function App() {
    const handleSet = () => {
        sCount.set(1);
    };

    const handleUp = () => {
        sCount.set(pre => (pre.value += 1));
    };

    return (
        <div>
            <h1>{sCount.html}</h1>
            <button onClick={handleSet}>Set 1</button>
            <button onClick={handleUp}>UP 1</button>
        </div>
    );
}

Pressing the button will change the value of Signify and will be automatically updated on the interface.

Advanced features

Use

The feature allows retrieving the value of Signify and using it as a state of the component.

import { signify } from 'react-signify';

const sCount = signify(0);

export default function App() {
    const countValue = sCount.use();
    const handleUp = () => {
        sCount.set(pre => {
            pre.value += 1;
        });
    };

    return (
        <div>
            <h1>{countValue}</h1>
            <button onClick={handleUp}>UP</button>
        </div>
    );
}

watch

The feature allows for safe tracking of the value changes of Signify.

import { signify } from 'react-signify';

const sCount = signify(0);

export default function App() {
    const handleUp = () => {
        sCount.set(pre => {
            pre.value += 1;
        });
    };

    sCount.watch(value => {
        console.log(value);
    });

    return (
        <div>
            <button onClick={handleUp}>UP</button>
        </div>
    );
}

Wrap

The feature applies the value of Signify in a specific interface area.

import { signify } from 'react-signify';

const sCount = signify(0);

export default function App() {
    const handleUp = () => {
        sCount.set(pre => (pre.value += 1));
    };
    return (
        <div>
            <sCount.Wrap>
                {value => (
                    <div>
                        <h1>{value}</h1>
                    </div>
                )}
            </sCount.Wrap>
            <button onClick={handleUp}>UP</button>
        </div>
    );
}

Hardwrap

The feature applies the value of Signify in a specific interface area and limits unnecessary re-renders when the parent component re-renders.

import { signify } from 'react-signify';

const sCount = signify(0);

export default function App() {
    const handleUp = () => {
        sCount.set(pre => (pre.value += 1));
    };
    return (
        <div>
            <sCount.HardWrap>
                {value => (
                    <div>
                        <h1>{value}</h1>
                    </div>
                )}
            </sCount.HardWrap>
            <button onClick={handleUp}>UP</button>
        </div>
    );
}

reset

A tool that allows restoring the default value. Helps free up resources when no longer in use.

import { signify } from 'react-signify';

const sCount = signify(0);

sCount.reset();

See more