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 [hash, setHash] = useHash("initial");
// or
const [hash, setHash] = useHash("initial", (newHash) => console.log('callback'));
// or
const [hash, setHash] = useHash();
// or
const [hash, setHash] = 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;
}
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