From 500c1469375a5dd7460aade3ff1d3e6e2a7d1b15 Mon Sep 17 00:00:00 2001 From: Todd Date: Tue, 16 Feb 2021 11:06:50 -0500 Subject: [PATCH] Remove key on reset as per the docs https://recoiljs.org/docs/guides/atom-effects/#asynchronous-storage-persistence when reseting we should remove the key completely. It will re-hydrate next run. --- src/index.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index e59af0b..1285b14 100644 --- a/src/index.ts +++ b/src/index.ts @@ -46,7 +46,13 @@ export const recoilPersist = ( onSet((newValue) => { const state = getState() - state[node.key] = newValue + + if (newValue instanceof DefaultValue) { + if(state.hasOwnProperty(node.key)) delete state[node.key]; + } else { + state[node.key] = newValue + } + setState(state) }) }