This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |