valtio
Version:
🧙 Valtio makes proxy-state simple for React and Vanilla
33 lines (32 loc) • 906 B
TypeScript
export declare const isProxyMap: (obj: object) => boolean;
/**
* proxyMap
*
* This is to create a proxy which mimic the native Map behavior.
* The API is the same as Map API
*
* @example
* import { proxyMap } from 'valtio/utils'
* const state = proxyMap([["key", "value"]])
*
* // can be used inside a proxy as well
* const state = proxy({
* count: 1,
* map: proxyMap()
* })
*
* // When using an object as a key, you can wrap it with `ref` so it's not proxied
* // this is useful if you want to preserve the key equality
* import { ref } from 'valtio'
*
* const key = ref({})
* state.set(key, "value")
* state.get(key) //value
*
* const key = {}
* state.set(key, "value")
* state.get(key) //undefined
*/
export declare function proxyMap<K, V>(entries?: Iterable<[K, V]> | undefined | null): Map<K, V> & {
$$valtioSnapshot: Omit<Map<K, V>, "set" | "delete" | "clear">;
};