Skip to content

ymzuiku/redux-auto-local-storage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Use

兼容 immutable 和普通 js 对象, 读取 store.getState()中的值,如果改变就本地持久化

import reduxAutoLocalStorage from "redux-auto-local-storage";
reduxAutoLocalStorage(store, "local-name", ["user", "data"]);

如果未使用 combineReducers, 添加一个 reducer 处理:

function reducer(state, action){
    if (action.type === "all_auto_local_storage") {
       return {...state, ...action.payload};
    }
}

如果使用了 combineReducers, 为每个需要本地化的subReducer添加一个 reducer 处理:

// userReducer
function user(state, action){
    // type 等于 state的键加'_auto_local_storage'
    if (action.type === "user_auto_local_storage") {
       return {...state, ...action.payload};
    }
}

reduxAutoLocalStorage 会在读取到属性时进行本地化

About

redux-auto-local-storage

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published