useHash
Manages URL hash value.
Usage
import { useHash } from "@siberiacancode/reactuse";
const hash = useHash("section");Example
initialValue:
Initial hash value.
const hash = useHash("intro");enabled:
Enables or disables hash tracking and updates.
const hash = useHash({ enabled: false });mode:
Controls how the hash is written ("initial" preserves existing hash, "replace" updates it).
const hash = useHash({ mode: "initial" });onChange:
Called when the hash changes.
const hash = useHash({ onChange: (value) => console.log(value) });Type Declarations
export interface UseHashOptions {
enabled?: boolean;
mode?: "initial" | "replace";
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;
}
export declare const useHash: UseHash;