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-redux-local-state

v1.0.7

Published

A simple react higher order component which automagically uses redux to handle local react state.

Readme

react-redux-local-state

A react higher order component (HOC) which automagically uses redux instead of local React state. Use it to expose an existing component's local state to redux or to write new redux ready components without the boilerplate

Usage

Step 1 - Connect reducer to redux

import { createStore, combineReducers } from 'redux'
import { reducer as localStateReducer } from 'react-redux-local-state'

const rootReducer = combineReducers({
  localState: localStateReducer
  // other reducers here
})

const store = createStore(rootReducer)

Note: by default the reducer's state slice is named is localState, if you need to use a different name you can do so, but the name will have to be passed in the options of each enhancer call.

Step 2 - Enhance your component

import { Enhancer } from 'react-redux-local-state'
import YourComponent from './YourComponent'

// with default options
const EnhancedComponent = Enhancer('componentName')(YourComponent)

export EnhancedComponent


// with custom options
let options = {
  componentName: 'otherComponentName',
  propName: 'someOtherPropName'
}

const EnhancedComponentWithOptions = Enhancer('componentName', options)(YourComponent)



export EnhancedComponentWithOptions

That's it! All of the enhanced component's local state will now be handled by redux. Any calls to this.setState will fire the 'RRLS_SET_COMPONENT_STATE' action. The component's this.state will be automatically be updated to match the redux store.

Customizing connect's arguments

All enhanced components connect to redux's store to listen to updates to state. If you want to pass custom mapStateToProps or mapDispatchToProps to connect, pass them as fields in the enhancer's option argument. The enhancer will automatically merge the results of your supplied arguments with its own and pass them to the component.

Custom arguments for connect's mergeProps and options are not currently supported.

Props

By default the component will get the setComponentState function and the rrls_localState object as props. If you need to change the name of these props to avoid collisions, you can set the actionName or propName fields in the option object.

Caveats

If you have multiple components with the same componentName, they will all share the same state.

This HOC functions by completely overwriting the enhanced component's setState method. super.setState is never called. This has a few implications:

  1. If the component is wrapped in another HOC which overwrites the setState method, or if the component itself overwrites the method, this HOC won't work properly.
  2. Normally, this.setState is batched by react. Components enhanced with this HOC instead receive their own local state as a prop. As a result, the internal batching isn't used. This shouldn't affect most component, but could potentially cause issues if the enhanced component somehow relies on the specifics of this internal batching.
  3. While this batching isn't used, the overwritten this.setState still won't guarantee that an immediate call to this.state will be updated. A callback should still be used if you need to immediately access an updated this.state

TODO

  • better error handling
  • tests