1
0
mirror of https://github.com/checktheroads/hyperglass synced 2024-05-11 05:55:08 +00:00
2020-12-13 01:49:13 -07:00

16 lines
480 B
TypeScript

import { useCallback, useMemo } from 'react';
import { useConfig } from '~/context';
import { flatten } from '~/util';
import type { TDevice } from '~/types';
export function useDevice(): (i: string) => TDevice {
const { networks } = useConfig();
const devices = useMemo(() => flatten<TDevice>(networks.map(n => n.locations)), []);
function getDevice(id: string): TDevice {
return devices.filter(dev => dev.name === id)[0];
}
return useCallback(getDevice, []);
}