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

redux-persist-little

v0.1.2

Published

对 redux 的状态进行持久化,支持多种存储方式如: localStorage、sessionStorage、localforage 或者react-native AsyncStorage 等

Downloads

21

Readme

redux-persist-little

对 redux 的状态进行持久化,支持多种存储方式如: localStorage、sessionStorage、localforage 或者react-native AsyncStorage 等

安装

yarn

yarn add redux-persist-little

npm

npm install redux-persist-little --save

API

persist

  1. 包裹单个reducer
import {persist} from 'redux-persist-little';

const reducer = persist(countReducer, {
    //必传参数 存储的 键
    key: 'count',
    //可选参数 指定存储引擎,localStorage、sessionStorage、localforage 或者react-native AsyncStorage 等
    storage: window.localStorage,
    //可选参数 过期时间,单位毫秒,不传或者传null是不过期
    expired: 1000 * 60 * 60 * 24
})
  1. 当做 combineReducers 使用,是对 combineReducers 的封装,可一次设置多个持久化状态

import {persist} from 'redux-persist-little';

const reducer = persist(
    {
        count: countReducer,
        count2: countReducer,
    },
    {
        // 可选参数 白名单,指定需要持久化的状态
        whiteList: ['count'],
        // 可选参数 黑名单,排除不需要持久化的状态,优先级比白名单低,设置了白名单就不会生效
        blackList: ['count2'],
        // 可选参数 存储的键前缀, 例如 count 存储的键就是 countPredix.count
        prefix: 'countPredix',
        //可选参数 指定存储引擎,localStorage、sessionStorage、localforage 或者react-native AsyncStorage 等
        storage: window.localStorage,
        //可选参数 过期时间,单位毫秒,不传或者传null是不过期
        expired: 1000 * 60 * 60 * 24
    },
)

DefaultStorage

设置默认的存储引擎,当调用 persist 时未传入 storage 时会使用


import {DefaultStorage} from 'redux-persist-little';
DefaultStorage.set(window.localStorage)

persistStore

开启store的恢复

import {createStore} from "redux";
import {persistStore} from 'redux-persist-little';

const store = createStore(reducer);

const persistor = persistStore(store);

PersistGate

一个 react 组件,包裹在组件的外层,会在store中的数据恢复完成后再渲染我们的组件

import {Provider} from "react-redux";
import {PersistGate} from 'redux-persist-little';

const App = () => {
    return (
        <Provider store={store}>
            <PersistGate persistor={persistor}>
                <Root />
            </PersistGate>
        </Provider>
    )
}