Remove key as required param for setItem
See original GitHub issueimport React from "react";
export default function useLocalStorage(key: string) {
const [item, setValue] = React.useState(() => window.localStorage.getItem(key));
const setItem = (item: string) => {
setValue(item);
window.localStorage.setItem(key, item);
};
return [item, setItem];
}
this should work just fine since key is captured by the closure?
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
Remove an element from the key of the localStorage session ...
This is not how to remove an element from an array, delete keyword works with deleting object properties. With arrays, you can use...
Read more >Storage.removeItem() - Web APIs - MDN Web Docs
The removeItem() method of the Storage interface, when passed a key name, will remove that key from the given Storage object if it...
Read more >localStorage in JavaScript: A complete guide - LogRocket Blog
getItem () accepts only one parameter, which is the key , and returns the ... To delete local storage sessions, use the removeItem()...
Read more >setItem(), getItem(), removeItem() clear() and key() Example
In this video, we will learn JavaScript LocalStorage methods - setItem (), getItem (), removeItem() clear() and key () with examples.
Read more >Storage removeItem() Method - W3Schools
The removeItem() method removes the specified Storage Object item. The removeItem() method belongs to the Storage Object, which can be either a localStorage ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@lilasquared I’ve updated the major version (now at v2.2.0 😉 after fixing some issues) as it was a breaking change.
I’ve also fixed some issues where form fields were uncontrolled initially.
@dance2die
I’ve put up a pull request to add @dance2die! 🎉