Skip to content

useHash ​

Hook that manages the hash value

state
low
test coverage
Last changed: 22 hours ago

Installation ​

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

Usage ​

typescript
const [hash, setHash] = useHash("initial", { enabled: true, mode: "replace", onChange: (newHash) => console.log('Hash changed:', newHash) });
// or
const [hash, setHash] = useHash("initial", (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

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;
}

type UseHashReturn = [string, (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 ​

Source • Demo

Contributors ​

D
debabin
debabin
H
hywax
hywax

Released under the MIT License.