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

@pietro-marino/reactjs-store

v1.0.3

Published

A React.js store made with useContext and useReducer like redux

Readme

reactjs-store

A modern, simple, useful and powerful React.js store made with useContext and useReducer like reduxjs with redux-actions plugin support.

It is made to create a ready-to-go store in a moment by writing less code by calling just a createStore function.

Like redux the initial state is created by the reducers registered by you, the library call them with the @@PM_REACT_STORE_INIT action.

Installation

Inside of your project install the library with the following command:

npm install --save @pietro-marino/reactjs-store

or

yarn add @pietro-marino/reactjs-store

How to use

Create the actions with the createAction function, like this:

import createAction from "@pietro-marino/reactjs-store/createAction";

export const INCREMENT = "INCREMENT";
export const DECREMENT = "DECREMENT";

export const increment = createAction(INCREMENT);
export const increment = createAction(DECREMENT);

Now, you have three method to create all reducer you need:

  1. write it, for example:
  const INITIAL_STATE = { value: 0 };

  export default function myReducer(state = INITIAL_STATE, action) {
    let newState = null;
    const payload = action.payload;
    switch(action.type) {
      case 'increment':
        newState = { value: state.value++ };
        break;
      case 'decrement':
        newState = { value: state.value-- };
        break;
      default:
        newState = state;
    }
    return newState;
  }
  1. if the reducer only handles an action you can create it by calling the built-in function called handleAction:
import handleAction from "@pietro-marino/reactjs-store/handleAction";

const INITIAL_STATE = { value: 0 };

const myReducer = handleAction('increment', (state, action) => {
  return { value: state.value++ };
}, INITIAL_STATE);

export default myReducer;
  1. to avoid using the switch you can use the handleActions function:
import handleActions from "@pietro-marino/reactjs-store/handleActions";

const INITIAL_STATE = { value: 0 };

function increment(state, action) {
  return { value: state.value++ };
}

function decrement(state, action) {
  return { value: state.value++ };
}

const myReducer = handleActions({
  'increment': increment,
  'decrement': decrement
}, INITIAL_STATE);

export default myReducer;

Finally, you can create the store and some utilities you need with createStore function. This function create for you:

  • the Provider component

  • the Consumer component

  • useStore hook to use state and the dispatcher within your functional component

    const [state, dispatch] = useStore();
  • useSelector hook to extract a portion of the state

    const [state, dispatch] = useSelector(state => state['key']);
  • useDispatch hook to extract only the dispatcher from useStore, if help you

    const dispatch = useDispatch();

So, with only one line of code you can create them all, like this:

  import createStore from "@pietro-marino/reactjs-store";

  export const {
    Provider,
    Consumer,
    useStore,
    useSelector,
    useDispatch
  } = createStore(myReducer);

Last but not least, for example we use the store created above, in your application:

App.js

import React from "react";
import { Provider } from "wherever you have created your store";

export default function App () {
  return (
    <Provider>
      <Counter />
    </Provider>
  );
}

Counter.js

import React from "react";
import { useStore } from "wherever you have created your store";
import { increment, decrement } from "wherever you have created your actions";

export default function Counter () {
  const [state, dispatch] = useStore();
  const incrementCount = dispatch(increment());
  const decrementCount = dispatch(decrement());

  return (
    <div className="counter">
      <div>
        Count: <span>${state.value}</span>
      </div>
      <div className="counter-actions">
        <button onClick={incrementCount}>+</button>
        <button onClick={decrementCount}>-</button>
      </div>
    </div>
  );
}

Advanced uses

You can combine actions to simplify the reducers:

import handleActions from "@pietro-marino/reactjs-store/handleActions";
import combineActions from "@pietro-marino/reactjs-store/combineActions";

const INITIAL_STATE = { value: 0 };

function increment(state, action) {
  return { value: state.value++ };
}

function decrement(state, action) {
  return { value: state.value++ };
}

function reset(state, action) {
  return { value: 0 };
}

const myReducer = handleActions({
  'increment': increment,
  'decrement': decrement,
  [combineActions("reset", "setZero")]: reset
}, INITIAL_STATE);

export default myReducer;

Combine reducers to a root reducer, like this:

import combineReducers from "@pietro-marino/reactjs-store/combineReducers";

const reducerOne = (state, action) => {};
const reducerTwo = (state, action) => {};
const reducerThree = (state, action) => {};

const rootReducer = combineReducers({
  'one': reducerOne,
  'two': reducertwo,
  'three': reducerThree
});

import createStore from "@pietro-marino/reactjs-store";

export const {
  Provider,
  Consumer,
  useStore,
  useSelector,
  useDispatch
} = createStore(myReducer);

// useful selectors
export const useOneSelector = () => useSelector(state => state['one']);
export const useTwoSelector = () => useSelector(state => state['two']);
export const useThreeSelector = () => useSelector(state => state['three']);

Examples

Inside the examples folder you can find a todo-app example that use this library.

License

@pietro-marino/reactjs-store is MIT licensed.