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-connected-reducers

v0.3.0

Published

Extends the Reducer React Hook to allow for components to share their reducer state with each other.

Downloads

19

Readme

react-connected-reducers

Version Downloads Build Status

react-connected-reducers extends the useReducer Hook to allow for components to share their reducer state with each other. If your are not familiar with Hooks or the useReducer Hook you should take a look at their introduction and the documentation for state hooks. For now this library is an experiment, that tries to enable React developers to connect components more easily, without having to rely on Redux or other state management frameworks.

Getting started

Install

$ npm install --save react-connected-reducers

Usage Example

import { ConnectedProvider, useConnectedReducer } from 'react-connected-reducer'

function useTodosReducer () {
  return useConnectedReducer('todos', (state, action) => {
    const { type, payload } = action;

    if (type === 'add') {
      return [...state, payload]
    }

    return state;
  }, [])
}

function TodoList () {
  const [todos] = useTodosReducer()

  return (
    <ul>
      {todos.map(todo => (
        <li>{todo}</li>
      ))}
    </ul>
  )
}

function TodoForm () {
  const [, dispatch] = useTodosReducer()

  let todoEl = useRef(null)

  const addTodo = e => {
    e.preventDefault()
    if (todoEl.current) {
      dispatch({ type: 'add', payload: todoEl.current.value })
      todoEl.current.value = ''
    }
  }

  return (
    <form onSubmit={addTodo}>
      <input ref={todoEl} type="text" />
      <button type="submit">Add todo</button>
    </form>
  )

  function App () {
    return (
      <ConnectedProvider>
        <TodoList />
        <TodoForm />
      </ConnectedProvider>
    )
  }
}

This example shows that useConnectedReducer works almost exactly like useReducer, with two differences:

  1. useConnectedReducer takes three arguments instead of two. The first one is the namespace, which is just a string. This namespace has to be unique through your whole application.

  2. We wrapped all elements in a ConnectedProvider. This component provides the state for all of our namespaces. Components using connected reducers need to be ancestors (not direct children) of a ConnectedProvider. To debug the state of your namespaces you can find them in this component i.e. using React Dev Tools.

That's all. Your are now ready to connect your components at ease!

API

useConnectedReducer(namespace, reducer, initialState) : [state, dispatch]

Parameters

namespace : string

Namespace for this reducer, unique through your whole application.

reducer : (state, action) => state

Function that takes a state and an action and returns a new state.

initialState : state

The inital state for the reducer.

Returns

state : state

The current state of the reducer.

dispatch : action => void

Use this function to run an action through this reducer.

Alternatives

  • Hookleton takes a more generalistic approach by providing a way to create hooks and store their logic and return values in memory to share it between components.