Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save leslie-alldridge/5c3a6866f00f5c7ad9e6fafad7a40f52 to your computer and use it in GitHub Desktop.
Save leslie-alldridge/5c3a6866f00f5c7ad9e6fafad7a40f52 to your computer and use it in GitHub Desktop.
local storage
const localStorage = global.window.localStorage;
export function get(key) {
return localStorage.getItem(key);
}
export function set(key, value) {
if (value === null) {
localStorage.removeItem(key);
} else {
localStorage.setItem(key, value);
}
}
export function remove(key) {
localStorage.removeItem(key);
}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
handleUpVote = () => {
let votesUsed = get("voted");
if (votesUsed >= 3) {
alert("No votes remaining");
} else {
set("voted", Number(votesUsed) + 1);
this.props.onVote(this.props.id);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment