1
0
Fork 1
mirror of https://github.com/thatmattlove/hyperglass.git synced 2026-01-17 08:48:05 +00:00
thatmattlove-hyperglass/hyperglass/ui/hooks/useDevice.ts
2021-02-10 00:43:40 -07:00

20 lines
564 B
TypeScript

import { useCallback, useMemo } from 'react';
import { useConfig } from '~/context';
import type { TDevice } from '~/types';
import type { TUseDevice } from './types';
/**
* Get a device's configuration from the global configuration context based on its name.
*/
export function useDevice(): TUseDevice {
const { networks } = useConfig();
const devices = useMemo(() => networks.map(n => n.locations).flat(), []);
function getDevice(id: string): TDevice {
return devices.filter(dev => dev._id === id)[0];
}
return useCallback(getDevice, []);
}