Registry / storage / redux-localstorage-filter

redux-localstorage-filter

JSON →
library0.1.1jsnpmunverified

A lightweight storage enhancer for redux-localstorage that selectively persists only a subset of the Redux state tree. Version 0.1.1 is the latest stable release, with no recent updates. It allows specifying paths (including nested keys joined by dots) to whitelist state properties for persistence. Unlike generic redux-localstorage middlewares that persist the entire state, this enhancer gives granular control. It is designed for use with the redux-localstorage ecosystem and requires redux-localstorage as a peer dependency. No TypeScript types are shipped.

npm install redux-localstorage-filter
INSTALL
IMPORT
SIG · REDUX-LOCALSTORAGE
R
redux-localstorage-filter
storagejavascriptv0.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

filter
import filter from 'redux-localstorage-filter'
import { filter } from 'redux-localstorage-filter'
This package has a default export, not a named export. Use default import syntax.
compose
import { compose } from 'redux-localstorage'
import { compose } from 'redux-localstorage-filter'
compose is from redux-localstorage, not from this package.
filter (CommonJS)
const filter = require('redux-localstorage-filter')
const { filter } = require('redux-localstorage-filter')
CommonJS require returns the default export. Destructuring will result in undefined.

Shows how to use the filter enhancer to persist only the 'user.token' path from the Redux state.

import filter from 'redux-localstorage-filter'; import localstorage from 'redux-localstorage'; import { compose, createStore } from 'redux'; const storageEnhancer = compose( filter('user.token'), )(localstorage(window.localStorage)); const store = createStore( (state) => state, compose( storageEnhancer ) );
Debug
Known issues
gotchaThe filter paths use dot notation for nested keys but do not support array indices or wildcards. To filter a nested key like 'a.b.c', use filter('a.b.c'). Passing an array like ['a.b', 'c.d'] is supported.
fix
Use dot-separated strings for nested keys. For arrays, specify the index as a string? (Note: this package does not support arrays explicitly; test your use case.)
affects: >=0.1.0
gotchaThis package depends on redux-localstorage as a peer dependency. If redux-localstorage is not installed, the enhancer will fail at runtime with a missing module error.
fix
Install redux-localstorage: npm install redux-localstorage
affects: >=0.1.0
breakingIn version 0.1.0, the package was originally written in JavaScript and had no TypeScript definitions. There is no plan to ship types.
fix
If using TypeScript, declare a module: declare module 'redux-localstorage-filter' { export default function filter(paths: string | string[]): Function; }
affects: 0.1.0
Errors
Common errors & fixes
TypeError: (0 , _reduxLocalstorageFilter.default) is not a function
Importing filter as a named export instead of default.
fix
Use import filter from 'redux-localstorage-filter' instead of import { filter } from 'redux-localstorage-filter'
Cannot find module 'redux-localstorage'
Missing peer dependency redux-localstorage.
fix
Run npm install redux-localstorage
TypeError: Cannot read property 'filter' of undefined
Calling filter on the result of compose without proper arguments or path string is empty.
fix
Ensure filter is called with a non-empty string or array of strings, and compose returns an enhancer that is applied correctly.
Upgrade
Version history
0.1.1latest on npm
Audit
Dependencies
redux-localstoragerequiredThis is a storage enhancer for redux-localstorage; you must have redux-localstorage installed to use it.
Agent activity
27 hits · last 30 days
node
22
Amazon
1
OpenAI (training)
1
Resources
redux-localstorage-filter — npm install redux-localstorage-filter · libregistry