Why use redux-persist over manually persisting state to localStorage?

夙愿已清 提交于 2019-12-03 16:10:14
Pritish Vaidya

The usage of redux-persist depends upon the use case of the application.

First, let me highlight some of the main features of redux-persist

  • Usage of PersistGate which automatically provides a delay in rendering of the components until the state gets persisted along with the usage to show the loading component.

  • Custom functions to persist based on multiple types such as persistStore, persistReducer and persistObject

  • AutoMerging of the initialStates from the different states based on shallow and deep levels

  • Probably the most important feature of blacklisting and whitelisting the reducers

  • Nested Persistence for shallow level persistence and deep level persistence

  • Persisting with migrations to store different versions of the redux-store.

  • Transforms to support immutable, compression, encrypt, filter, etc.

Considering the application you build is just for development purposes, then it would require at most PersistGate, persistStore and probably blacklist and whitelist of the reducers, which would still be considerable amount of work considering that you are aware what you might need for your application.

Now for the applications that are production level and are prone to scaling, then it would be requiring at least 5 / 7 features that I have listed above. Without this module you might need to install modules for compression, encryption and much more, find a way to gracefully store different versions of the redux-store and retrieve and display what might fit your requirement, along with the rehydration of that redux-store state.

There are many more implications to this, which will be encountered later on. Therefore based on the requirements of the project, I think it would be beneficial to use this package, to manage the redux-store storage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!