useMap

    API

    import useMap from '@restart/hooks/useMap'
    • useMap<K, V>(init?: Iterable<Readonly<[K,V]>>) => ObservableMap<K, V>

      Create and return a Map that triggers rerenders when it's updated.

      const customerAges = useMap<number>([
      ['john', 24],
      ['betsy', 25]
      ]);
      return (
      <>
      {Array.from(ids, ([name, age]) => (
      <div>
      {name}: {age}. <button onClick={() => ids.delete(name)}>X</button>
      </div>
      )}
      </>
      )

      Parameters

      • init?Iterable<Readonly<[K,V]>>

        initial Map entries

      Return Value ObservableMap<K, V>