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
Name | Type | Default | Note |
---|---|---|---|
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
Name | Type | Default | Note |
---|---|---|---|
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 • DemoContributors ​
D
H