ghost-portal/packages/page-bounties/src/useCounter.ts
2022-01-01 09:30:15 +02:00

20 lines
582 B
TypeScript

// Copyright 2017-2022 @polkadot/app-bounties authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { useMemo } from 'react';
import { DeriveBounties } from '@polkadot/api-derive/types';
import { createNamedHook, useApi, useCall } from '@polkadot/react-hooks';
function useCounterImpl (): number {
const { api, isApiReady } = useApi();
const bounties = useCall<DeriveBounties>(isApiReady && api.derive.bounties?.bounties);
return useMemo(
() => bounties?.length || 0,
[bounties]
);
}
export default createNamedHook('useCounter', useCounterImpl);