Comments (4)
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.
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.
Related: #253
from usehooks.
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)
- UseMeasure ref ts error HOT 1
- React 17 as peer dependency ? HOT 2
- Can't stop propagation with useClickAway HOT 3
- Type 'MutableRefObject<Element>' is not assignable to type 'LegacyRef<HTMLDialogElement> | undefined'. HOT 1
- useScript should return loaded when script is already in the page HOT 6
- useLocalStorage only allows strings that can be JSON.parse'd HOT 2
- Error: useLocalStorage is a client-only hook - thrown from a client component HOT 8
- FR: useEffectOnce() and useUpdateEffect() HOT 1
- wrong text is copied HOT 3
- useMediaQuery causes error when used with Nextjs (not server safe) HOT 2
- Add documentation on how to use client-hooks and improve errors HOT 2
- Request: Bring back code snippets HOT 1
- 🪲 BUG: Can't use the hooks on contextAPI file in NextJs14 HOT 1
- Where is the source code? HOT 1
- useHover has incorrect state when the component is mounted below the cursor
- Error when running react-script test with jest HOT 3
- jest test arent passing HOT 1
- ERROR: Cannot assign to import "useEffectEvent" when importing useKeyPress hook HOT 5
- useMediaQuery not working on iPhone 6 with iOS 12.5.7 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from usehooks.