astoilkov/use-local-storage-state

Hooks sets localStorage value to string 'undefined' rather than doing nothing.

ozyman42 opened this issue · 2 comments

const [storedData, setStoredData, { removeItem }] = useLocalStorageState("testing");
const value = localStorage.getItem('testing')
console.log(typeof value);
console.log(value)

this outputs

string
undefined

this should ideally output

object
null

Why is the hook updating local storage when the client code never instructs it to do so?

This is caused by the change that was made when resolving #26.

Probably I shouldn't write the value on the initial render when a value isn't passed.

I just made a new release that includes the change. Thanks for reporting!