when have time, will organize this post
Reason for using
- saving code to persist a large amount of state
-
Simple codes (3 lines)
123import {persistStore, autoRehydrate} from ‘redux-persist’const store = createStore(reducer.., autoRehydrate())persistStore(store) -
persistStore(store, [config, callback])
Generating apersistor
forstore
and use autoRehydrate (enhancer) to rehydration action’s dispatch
what is enhancer? A way to replace our chunky codes with localStorage stuff
what is persistor? It subscribes to store changes
can use blacklist (ignore), whitelist (only), storage engine, transforms (immutable, compress, encrypt, filter..), config obj
Callback rehydration (changing obj to state)
Can be chained
近期评论