Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can we modify the keyPrefix #137

Closed
iroy2000 opened this issue Jul 19, 2016 · 12 comments
Closed

How can we modify the keyPrefix #137

iroy2000 opened this issue Jul 19, 2016 · 12 comments

Comments

@iroy2000
Copy link
Contributor

Currently the keyPrefix is hardcoded as constant, would that be a good feature if people can overwrite it ??

https://github.com/rt2zz/redux-persist/search?utf8=%E2%9C%93&q=keyPrefix

@iroy2000
Copy link
Contributor Author

iroy2000 commented Jul 20, 2016

Ok, answering my own questions, you actually can do that in your application before you configure your store

require('redux-persist/constants').keyPrefix = 'something_else';

And your key will be changed.

@rt2zz
Copy link
Owner

rt2zz commented Jul 21, 2016

Why do you want to change the key prefix? I think this will be a very rare use case, and your solution works.

@benlangfeld
Copy link

One common use case is to store (non-sensitive) data for multiple users of the app. I would use a user ID as the key prefix.

Another is to serve multiple Redux apps on a single domain, with their persisted state namespaced.

I think it's important to have a first-class API for this.

@jschr
Copy link

jschr commented Aug 3, 2016

+1 for this feature as well. Ideally you wouldn't set this globally but could set it on store creation (perhaps as input to a store enhancer?). My specific use case is in my app I create multiple redux stores for managing state (a single global store for db/auth state + local component stores for ui state). I'm only persisting global state at the moment but I could see adding the ability to persist certain parts of ui state as well.

Strictly for aesthetics, it would also be nice to just remove the prefix altogether. I'm using redux-persist in a chrome packaged app and wrote a small storage adapter to persist to chrome.storage.local where the key prefix isn't really necessary. This is definitely a minor nit-pick.

That's my 2 cents, thanks for the great lib regardless!

@rt2zz
Copy link
Owner

rt2zz commented Aug 17, 2016

thanks for the input, sounds like we definitely need configurable keyPrefix :)

This would be trivial to implement as a config option keyPrefix

@benlangfeld
Copy link

❤️

@rt2zz
Copy link
Owner

rt2zz commented Aug 18, 2016

I will cut a release soon, hopefully tomorrow 👍

@jonathan-stone
Copy link

It would be great to mention this in the docs.

@iroy2000
Copy link
Contributor Author

👍 But is that mentioned in the doc ?

@rt2zz
Copy link
Owner

rt2zz commented Aug 31, 2016

It would be good to add this to the config options in the docs. PR appreciated!

@iroy2000
Copy link
Contributor Author

iroy2000 commented Sep 1, 2016

Ok @rt2zz , PR is here #160

@damianobarbati
Copy link

Very useful indeed.
@rt2zz I found this by accident and it was a luck: I have two different apps running on subpath /user and /admin and I'm using crosstabsync as well.
When both were opened in the browser they were endlessly "rehydrating" each other.
Thanks to prefix everything is fine (y)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants