Hacker News new | past | comments | ask | show | jobs | submit login

Not that I disagree with your other arguments but this one sticks out:

> Except if you want to store objects/arrays/numbers (localStorage only supports strings)

My normal usage of localStorage usually looks like this:

    const getItem = (item) => { JSON.parse(window.localStorage.getItem(item)) }
    // and
    const setItem = (item, val) { window.localStorage.setItem(item, JSON.stringify(val)) }
And then you won't have issues with any type.



Except when a value has already been stored previously without JSON.stringify (in which case JSON.parse will throw), or you need a default value if unset (e.g `store.get('username', 'anonymous')`, or ... :) But I also see your point that sometimes the very quick and simple solution can be useful!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: