recoil-persist icon indicating copy to clipboard operation
recoil-persist copied to clipboard

Reseting atom causes key to be empty instead of default value

Open toddmcbrearty opened this issue 3 years ago • 3 comments

When you reset the atom it becomes an empty state saved in storage. According to the docs https://recoiljs.org/docs/guides/atom-effects/#asynchronous-storage-persistence the key should be removed when it's a default value (at least for now)

the fix is to simply add this to onSet

if (newValue instanceof DefaultValue) {
      if(state.hasOwnProperty(node.key)) delete state[node.key];
} else {
     state[node.key] = newValue
}

toddmcbrearty avatar Feb 16 '21 16:02 toddmcbrearty

I have released a new 2.3.0 version with your fix.

polemius avatar Feb 16 '21 21:02 polemius

This is still not working in version 2.4.0

ramiel avatar Mar 13 '21 21:03 ramiel

The new version 2.5.0 with fix just released.

polemius avatar Mar 14 '21 21:03 polemius