store icon indicating copy to clipboard operation
store copied to clipboard

Is there any way to change the persistState key based on the route

Open chinra02 opened this issue 10 years ago • 2 comments

Is there any way we can pass the key dynamically, i am working on an app where same component are used in multiple tabs and need to store the user selections of this component for each tab with different key.

Right now i see the we are doing persistState as below with hard-coded key persistState('counter', { key: 'ng2-redux/examples/counter' })

I need to change the key based on the tab (implemented based on routes).

Let me know if i can do this with ng2-redux?

chinra02 avatar Nov 17 '16 19:11 chinra02

Hi @chinra02

persistState is actually provided by the redux-localstorage 3rd-party library, and is configurable with a range of options. Essentially the 'key' you see there is just a namespace prefix for your data in local storage; what actually gets persisted is the contents of your redux store.

You can have it persist the full store, or just parts of it as you wish: see their documentation for details: https://www.npmjs.com/package/redux-localstorage

So in your case I would save the settings for each tab in different parts of the store and let redux-localstorage persist the relevant portion of the store.

SethDavenport avatar Nov 19 '16 19:11 SethDavenport

Thanks for your reply. good idea !!!

chinra02 avatar Nov 21 '16 23:11 chinra02