Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #2560 setValue updated #2562

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions docs/useLocalStorage.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@ React side-effect hook that manages a single `localStorage` key.
import { useLocalStorage } from 'react-use';

const Demo = () => {
const [value, setValue, remove] = useLocalStorage('my-key', 'foo');
const [value, setValue] = useLocalStorage('my-key', 'foo');

return (
<div>
<div>Value: {value}</div>
<button onClick={() => setValue('bar')}>bar</button>
<button onClick={() => setValue('baz')}>baz</button>
<button onClick={() => remove()}>Remove</button>
<button onClick={() => setValue(prev => {
// You can use the `prev` value here to determine the new value
if (prev === 'foo') {
return 'bar';
} else {
return 'foo';
}
})}>
Toggle Value
</button>
</div>
);
};
Expand Down