useObject ​
Hook that provides state and helper methods to manage an object
state
test coverage
Last changed: 24 minutes ago
Installation ​
Library
CLI
Manual
typescript
import { useObject } from '@siberiacancode/reactuse';
Usage ​
typescript
const { value, set, reset, remove, update, merge, clear, toggle, has, keys, isEmpty, size } = useObject({ name: 'John', age: 30, isActive: true });
Demo ​
Api ​
Parameters
Name | Type | Default | Note |
---|---|---|---|
initialValue | Value | - | The initial object value |
Returns
UseObjectReturn<Value>
Type declaration ​
typescript
export interface UseObjectReturn<Value extends object> {
/** Checks if the object is empty */
empty: boolean;
/** Gets the keys of the object */
keys: Array<keyof Value>;
/** Gets the number of properties */
size: number;
/** The current object state */
value: Value;
/** Clears all properties from the object */
clear: () => void;
/** Checks if a property exists */
has: (key: keyof Value) => boolean;
/** Removes a property from the object */
remove: (key: keyof Value) => void;
/** Resets the object to its initial value */
reset: () => void;
/** Sets a property on the object */
set: (value: Partial<Value>) => void;
}
Source ​
Source • DemoContributors ​
D
A