Giter Site home page Giter Site logo

Comments (4)

philg-ygt avatar philg-ygt commented on June 14, 2024 1

I agree with @SteveVanOpstal here: the use of JSON.stringify adds further constraints to the already existing constraints in place when using localStorage.setItem.

If, for example, you decide to send in an object and thus get [object Object] back, that's on you for not supplying a primitive, same as if you were using .setItem directly. It isn't the place of a hook to serialise input, particularly when there is no corresponding deserialising of the output; there is no JSON.parse wrapping localStorage.getItem in getLocalStorageItem...

from usehooks.

ngoue avatar ngoue commented on June 14, 2024

I disagree that this belongs here as an issue. This is exactly how the standard was defined to behave:

https://stackoverflow.com/questions/1423081/json-left-out-infinity-and-nan-json-status-in-ecmascript

from usehooks.

tylermcginnis avatar tylermcginnis commented on June 14, 2024

Related: #253

from usehooks.

SteveVanOpstal avatar SteveVanOpstal commented on June 14, 2024

I disagree that this belongs here as an issue. This is exactly how the standard was defined to behave:

https://stackoverflow.com/questions/1423081/json-left-out-infinity-and-nan-json-status-in-ecmascript

It's not necessarily a software issue but coming across this I had the expectation, given that it's a blackbox function, that there were no restrictions. Only after looking at the source code I realised that it uses JSON.stringify to convert it to a string for localStorage, hence it is not able to handle Infinity and NaN. It might just come down to mentioning this in the docs.

from usehooks.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.