question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Remove key as required param for setItem

See original GitHub issue
import 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:closed
  • Created 5 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
dance2diecommented, Feb 10, 2019

@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.

0reactions
allcontributors[bot]commented, Feb 10, 2019

@dance2die

I’ve put up a pull request to add @dance2die! 🎉

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found