import { useMemo } from 'react';

/**
 * Hook to convert an array of code-color pairs into a Map mapping codes onto
 * colors.
 *
 * @typedef {Object} CodeColorPair
 * @property {string} code - the code of a boundary in a map
 * @property {string} color - a color name
 *
 * @param {CodeColorPair[]} codeColors
 * @returns {Map}
 */
const useCodeColors = function useCodeColors(codeColors) {
  return useMemo(() => new Map(codeColors.map(({
    code,
    color
  }) => [code, color])), [codeColors]);
};
export default useCodeColors;