ghost-portal/packages/react-hooks/src/useIncrement.ts
Jaco Greeff 64299ebd29
Dev bump (#4012)
* Bump API/Common (esnext exports)

* Bump deps

* Adjust

* Bumps

* Bumps

* repository

* Update dev

* Remove Rococo (for the time being)

* script extension
2020-11-11 15:28:52 +01:00

20 lines
587 B
TypeScript

// Copyright 2017-2020 @polkadot/react-hooks authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { useCallback, useState } from 'react';
import { useIsMountedRef } from './useIsMountedRef';
export function useIncrement (defaultValue = 1): [number, () => void, (value: number) => void] {
const mountedRef = useIsMountedRef();
const [value, setValue] = useState(defaultValue);
const increment = useCallback(
(): void => {
mountedRef.current && setValue((value: number) => ++value);
},
[mountedRef]
);
return [value, increment, setValue];
}