ghost-portal/packages/page-tech-comm/src/useCounter.ts
2021-01-03 11:33:39 +01:00

18 lines
542 B
TypeScript

// Copyright 2017-2021 @polkadot/app-democracy authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Hash } from '@polkadot/types/interfaces';
import { useApi, useCall } from '@polkadot/react-hooks';
const transformCounter = {
transform: (proposals: Hash[]) => proposals.length
};
export default function useCounter (): number {
const { api, isApiReady } = useApi();
const counter = useCall<number>(isApiReady && api.query.technicalCommittee?.proposals, undefined, transformCounter) || 0;
return counter;
}