When you call the setter with null (or undefined), the hook correctly removes the item from storage—but because of the fallback logic, it then returns the original initialValue instead of null (or undefined).
Steps to reproduce:
Install @uidotdev/usehooks
In your component:
const [value, setValue] = useLocalStorage<string>('foo', 'default');
setValue(null);
Observe that localStorage.getItem('foo') is removed, yet value === 'default'
Expected behavior:
After removal, the hook’s state should be null (or undefined), regardless of what initialValue was.
Actual behavior:
The hook returns initialValue whenever the stored item is missing.
When you call the setter with
null(orundefined), the hook correctly removes the item from storage—but because of the fallback logic, it then returns the originalinitialValueinstead ofnull(orundefined).Steps to reproduce:
Install
@uidotdev/usehooksIn your component:
Observe that localStorage.getItem('foo') is removed, yet value === 'default'
Expected behavior:
After removal, the hook’s state should be
null(orundefined), regardless of what initialValue was.Actual behavior:
The hook returns
initialValuewhenever the stored item is missing.