Skip to content

useHash

Hook that manages the hash value

state
low
test coverage
Last changed: last month

Installation

Library
CLI
Manual
typescript
import { useHash } from '@siberiacancode/reactuse';

Usage

typescript
const { value, set } = useHash("initial");
// or
const { value, set } = useHash("initial", (newHash) => console.log('callback'));
// or
const { value, set } = useHash();
// or
const { value, set } = useHash((newHash) => console.log('callback'));

Demo

Api

Parameters

NameTypeDefaultNote
initialValue?string-The initial hash value if no hash exists
options?UseHashOptions-Configuration options
options.enabled?boolean-The enabled state of the hook
options.mode?'initial' | 'replace'-The mode of hash setting
options.onChange?(hash: string) => void-Callback function called when hash changes

Returns

UseHashReturn

Parameters

NameTypeDefaultNote
initialValue?string-The initial hash value if no hash exists
callback?(hash: string) => void-Callback function called when hash changes

Returns

UseHashReturn

Parameters

NameTypeDefaultNote
options?UseHashOptions-Configuration options
options.enabled?boolean-The enabled state of the hook
options.mode?'initial' | 'replace'-The mode of hash setting
options.onChange?(hash: string) => void-Callback function called when hash changes

Returns

UseHashReturn

Parameters

NameTypeDefaultNote
callback?(hash: string) => void-Callback function called when hash changes

Returns

UseHashReturn

Type declaration

typescript
export interface UseHashOptions {
  /** The enabled state of the hook */
  enabled?: boolean;
  /** The mode of hash setting */
  mode?: 'initial' | 'replace';
  /** Callback function called when hash changes */
  onChange?: (hash: string) => void;
}

interface UseHashReturn {
  /** The hash value */
  value: string;
  /** The function to set the hash value */
  set: (value: string) => void;
}

export interface UseHash {
  (initialValue?: string, options?: UseHashOptions): UseHashReturn;

  (options?: UseHashOptions): UseHashReturn;

  (initialValue?: string, callback?: (hash: string) => void): UseHashReturn;

  (callback?: (hash: string) => void): UseHashReturn;
}

Source

SourceDemo

Contributors

D
debabin
debabin
H
hywax
hywax

Released under the MIT License.