Skip to content

Instantly share code, notes, and snippets.

View Sheraff's full-sized avatar
🐙

Flo Sheraff

🐙
View GitHub Profile
import { useSyncExternalStore, useCallback } from "react";
/**
* Use for getting the value of given `key` in `localStorage`, or setting it.
*
* @param key - `localStorage` key we want to get its value, or change it
* @example
*
* ```tsx
* const [hello, setHello] = useLocalStorageKey("hello");
@Sheraff
Sheraff / nothing.js
Created February 2, 2021 20:42 — forked from joakim/nothing.js
The concept of nothing in JavaScript (Crockford's idea of a better undefined)
const nothing = new Proxy(Object.freeze(Object.create(null)), Object.create(null, {
get: { value(target, property) {
return property === Symbol.toPrimitive ? () => null : nothing }
}
}))
nothing.foo === nothing // true
nothing.foo.bar.baz[42].qux // nothing forever
typeof nothing === "object" // true