UNPKG

883 BTypeScriptView Raw
1export declare class ObservableMap<K, V> extends Map<K, V> {
2 private readonly listener;
3 constructor(listener: (map: ObservableMap<K, V>) => void, init?: Iterable<Readonly<[K, V]>>);
4 set(key: K, value: V): this;
5 delete(key: K): boolean;
6 clear(): void;
7}
8/**
9 * Create and return a [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) that triggers rerenders when it's updated.
10 *
11 * ```tsx
12 * const customerAges = useMap<number>([
13 * ['john', 24],
14 * ['betsy', 25]
15 * ]);
16 *
17 * return (
18 * <>
19 * {Array.from(ids, ([name, age]) => (
20 * <div>
21 * {name}: {age}. <button onClick={() => ids.delete(name)}>X</button>
22 * </div>
23 * )}
24 * </>
25 * )
26 * ```
27 *
28 * @param init initial Map entries
29 */
30declare function useMap<K, V>(init?: Iterable<Readonly<[K, V]>>): ObservableMap<K, V>;
31export default useMap;
32
\No newline at end of file