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