ghost-portal/packages/react-hooks/src/useAccountId.ts
Ewa Kowalska 541213f233
Ek extract type only imports into separate group (#4168)
* Plug new beta of eslint plugin simple import sort

* Apply new configuration to existing imports
2020-12-07 16:04:05 +01:00

22 lines
709 B
TypeScript

// Copyright 2017-2020 @polkadot/react-hooks authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { StringOrNull } from '@polkadot/react-components/types';
import { useCallback, useState } from 'react';
export function useAccountId (initialValue: StringOrNull = null, onChangeAccountId?: (_: StringOrNull) => void): [StringOrNull, (_: StringOrNull) => void] {
const [accountId, setAccountId] = useState<StringOrNull>(initialValue);
const _setAccountId = useCallback(
(accountId: StringOrNull = null): void => {
setAccountId(accountId);
onChangeAccountId && onChangeAccountId(accountId);
},
[onChangeAccountId]
);
return [accountId, _setAccountId];
}