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 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-data-stores

v1.4.1

Published

simple data shairing solution for shair data betwene compognent in react

Readme

React data stores

A simple state management solution that allows you to create a centralized stores for your application. This package provides a Store class to manage state and listen for changes.

📦 Installation

You can install this package via npm:

npm install react-data-stores

🚀 Usage

🔧 Creating a Store

You can create a new store by passing an initial state to the createStore function.

import createStore from "react-data-stores";

const dataStore = createStore({ counter: 0, times: 0 });

🔍 Accessing State

To access the current state of the store, use the useStore method.

const options = {
  getter: true, //if you want the getter
  setter: true, //if you want the setter function
};
const [currentState, setState] = dataStore.useStore(options);
// [{ counter: 0 ,times:0},setter function(){}]
🔸 options is optional.
🔸 By default, useStore() returns both the getter and setter as a  tuple.
🔸 If you pass { getter: true } or { setter: true } alone,
    useStore() will return just that one (not a tuple).
🔸 If both are true, it’s equivalent to calling useStore() with no options.

🔄 Updating State

You can update the state using the setState method. This method takes an object containing the new state values.

const [currentState, setState] = dataStore.useStore(); // [{ counter: 0 },setter function(){}]

setState({ counter: 1 }, true); //state={counter:1}
setState({ counter: 1 }, false); //state={counter:1,times:0}

setState accept two parameters first is the data and second is a boolean that indecate is the new state sholde overwrite the full store or just update the given keys by the new value

by default the value is false wich means just update and not overwrite the full store data

💡 Real Use Case Example

Here’s an example of how to create and use the store in a React component:

//dataStore.js

import createStore from "react-data-stores";

export const dataStore = createStore({ counter: 0 });

//CounterComponent.js

import React, { useState, useEffect } from "react";
import { dataStore } from "./dataStore"; // Import your Store

export default function CounterComponent() {
  //get the current state of the store
  const [data, setData] = dataStore.useStore();

  return (
    <div>
      <button
      onClick={
        () => {
          setData({ counter: data.counter 1 })
          }
        }>
        Increase {data.counter}
    </button>
    </div>
  );
}

🛠️ Helper Functions: getCurrent & setCurrent

These functions are available outside of React components, letting you read or update the store without needing to pass setters around.

⚠️ Note : getCurrent() returns the state at the time of the call. It won't cause a component to re-render when state changes. If you want reactivity, use useStore() instead.

use case

// store/counter.js
export const counterStore = createStore({ count: 0 });

// utils/counterUtils.js
export function incrementCounter() {
  const current = counterStore.getCurrent();
  counterStore.setCurrent({ count: current.count + 1 });
}

License

This package is licensed under the MIT License. See the LICENSE file for details.