soyguijarro / react-storage-hooks

React hooks for persistent state
https://npm.im/react-storage-hooks
MIT License
166 stars 18 forks source link

Provide option to omit specific keys from storage #6

Closed aratcliffe closed 4 years ago

aratcliffe commented 5 years ago

Hi, would you consider adding an option to omit specific keys from being saved to storage?

soyguijarro commented 5 years ago

Hi @aratcliffe, thanks for the suggestion. I guess you want this for the useLocalStorageReducer and useSessionStorageReducer hooks, right? My first impression is that I'm not sure I see much value in it, you can always put your non-persisted keys in a separate regular useReducer hook. Do you have a concrete use case example for this?

soyguijarro commented 4 years ago

Closing this as I didn't get any response and I still don't see a use case for this feature.

manzoorwanijk commented 4 years ago

We have a use case for this feature and we need it. We have a list of items for which we store the list filters using useReducer. We want to store certain filters using useStorageReducer but not all of them. For example the filter state looks like this:

{
    perPage: 6,
    pageNumber: 1,
    searchText: '',
    sortBy: 'id',
    view: 'card', // or 'table'
}

We want to store only view in local storage not the other keys.