@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
27 lines (21 loc) • 728 B
text/typescript
import { useEffect, useState } from "react";
import {
getDeviceInfoAction as defaultGetDeviceInfoAction,
GetDeviceInfoActionState,
initialState,
} from "../actions/getDeviceInfo";
export type UseGetDeviceInfoArgs = {
getDeviceInfoAction?: typeof defaultGetDeviceInfoAction;
deviceId: string;
};
export const useGetDeviceInfo = ({
getDeviceInfoAction = defaultGetDeviceInfoAction,
deviceId,
}: UseGetDeviceInfoArgs): GetDeviceInfoActionState => {
const [state, setState] = useState<GetDeviceInfoActionState>(initialState);
useEffect(() => {
const sub = getDeviceInfoAction({ deviceId }).subscribe(setState);
return () => sub.unsubscribe();
}, [deviceId, getDeviceInfoAction]);
return state;
};