Skip to content

Commit

Permalink
fix: prevent DefaultValue from being set when the localStorage state …
Browse files Browse the repository at this point in the history
…does not contain the key. Fixes polemius#26
  • Loading branch information
bartvanremortele committed Apr 16, 2021
1 parent 490fa83 commit a0821bf
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const recoilPersist = (
if (trigger === 'get') {
const state = getState()
if (typeof state.then === 'function') {
state.then((s) => {
state.then((s: any) => {
if (s.hasOwnProperty(node.key)) {
setSelf(s[node.key])
}
Expand All @@ -49,10 +49,9 @@ export const recoilPersist = (
if (
newValue !== null &&
newValue !== undefined &&
newValue instanceof DefaultValue &&
state.hasOwnProperty(node.key)
newValue instanceof DefaultValue
) {
delete state[node.key]
if (state.hasOwnProperty(node.key)) delete state[node.key]
} else {
state[node.key] = newValue
}
Expand Down

0 comments on commit a0821bf

Please sign in to comment.