1
0
mirror of https://github.com/checktheroads/hyperglass synced 2024-05-11 05:55:08 +00:00
2020-12-31 23:09:54 -07:00

22 lines
610 B
TypeScript

import { useCallback, useMemo } from 'react';
import { useConfig } from '~/context';
import { flatten } from '~/util';
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(() => flatten<TDevice>(networks.map(n => n.locations)), []);
function getDevice(id: string): TDevice {
return devices.filter(dev => dev.name === id)[0];
}
return useCallback(getDevice, []);
}