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

v0.0.1

Published

React component which giving you the ability to control state

Downloads

3

Readme

react-state-store

Give you the ability to decide when and what states to execute in setState

Version

Installation

npm install react-state-store --save

Why

Sometimes I have setState in different functions for seperating logic. Then when I try to use them in combination, I hope they can execute setState only one time so that it won't re-render too much.

this.setState({attribute1: name1})
callback(
	this.setState({attribute2: name2})
	(() => {
		this.setState({attribute3: name3})
	})(this);
)

But I hope execute setState only one time

Usage

1 . Require react-state-store after installation

import SetStore from "react-state-store" 

Method

set(state, alias)

Set(store) some state into StateStore, the function will give you an unique id so that you can get them by get(id), you can also set alias so that you can use get(alias) to get them.

Params:

  • state[object] : the state you want to execute in the future
  • alias [string] : so you can use get(alias) to get the state object you just set (optional)

Return:

  • id or alias
get(id)

Get specific state stored before, then this state will be removed from StateStore

Params:

  • id[string] : the id return by set(state, alias)

Return:

  • state object
getAll()

Get all state stored, then this function will remove all state stored in the StateStore

Return:

  • state object
remove(id)

Remove specific state in StateStore

removeAll()

Remove all state in StateStore

Example

import StateStore from "react-state-store";
import React from "react";

class Index extends React.Component {

  constructor() {
    super();
    this.state = {
      number: 0,
      string: "",
    }
  }
	 
  click() {
    StateStore.set({
      string: "example1",
      number: 1
    }, "first");
    
    StateStore.set({string: "example2"});
    
    setTimeout(() => {
      this.setState(StateStore.getAll());
      /* This equal to the following
        this.setState({
         string: example2,
         number: 1
        })
      */ 
    }, 5000);
    
  }

  render() {
    let {number, string} = this.state;
    return (
      <section>
        <p>String: {string}</p>
        <p>Number: {number}</p>
        <button onClick={this.click.bind(this)}>Button</button>
      </section>
    )
  }
}

React.render(<Index />, document.body);
	

License

MIT