unstated-persist
unstated-persist copied to clipboard
Cannot use dynamic persist key
If you want to use dynamic persist key, you are out of luck:
class Mu extends PersistContainer {
persist = {
key: "defaultKey",
version: 1,
storage: ...,
}
constructor(key) {
super()
this.persist.key = key // too late, container is already rehydrated
}
}
Hacky solution to this problem is to wrap it:
const Mu = (key) => new (class extends PersistContainer {
persist = {
key,
version: 1,
storage: ...,
}
}) ()
Does following work for you?
class Mu extends PersistContainer {
constructor(key) {
super()
this.persist = {
key,
version: 1,
storage: ...,
}
}
}