usePersistedState hook does not currently support removing an item. One option would be to remove the key if value given is null or undefined:
import { isNil } from 'lodash';
if (isNil(value)) {
storage.remove(key);
} else {
storage.set(key, value as any);
}
if (options?.urlKey) setUrlState(options?.urlKey, value as any);
...but this would not allow explicitly setting any key to null / undefined. Initially this feels like a good constraint, but there might be some case some day where explicit setting to null / undefined would be desirable, so not sure if this is the best solution.
usePersistedState hook does not currently support removing an item. One option would be to remove the key if value given is null or undefined:
...but this would not allow explicitly setting any key to null / undefined. Initially this feels like a good constraint, but there might be some case some day where explicit setting to null / undefined would be desirable, so not sure if this is the best solution.