ITADN

persistentBoolean initial has no sense

#57Opend8corp 创建于 2026-01-23
D
d8corpcommented
When I use `persistentBoolean('test', true)` it works ugly: it removes storage when value `false`. So if I reload the page there is no storage and it uses initial value `true`. Before reload it's `false`, after `true`. ```js export function persistentBoolean(key, initial = false, opts = {}) { return persistentAtom(key, initial, { ...opts, decode(str) { return str === 'yes' }, encode(value) { return initial === value ? undefined : initial ? 'no' : 'yes' // <--- CHANGE THIS } }) } ```
9 条评论