Files
js/@3rdweb-sdk/react/hooks/useActiveChainId.ts
T
2022-03-17 14:41:47 -07:00

18 lines
557 B
TypeScript

import { useSingleQueryParam } from "hooks/useQueryParam";
import {
getChainIdFromNetwork,
getNetworkFromChainId,
SUPPORTED_CHAIN_ID,
SupportedNetwork,
} from "utils/network";
export function useActiveChainId(): SUPPORTED_CHAIN_ID | undefined {
const networkFromUrl = useSingleQueryParam<SupportedNetwork>("network");
return getChainIdFromNetwork(networkFromUrl);
}
export function useActiveNetwork(): SupportedNetwork | undefined {
const activeChainId = useActiveChainId();
return activeChainId && getNetworkFromChainId(activeChainId);
}