useObjectState

Manage object state with partial updates.

https://www.shaktools.com/shak-hooks
State

API Reference

Installation

terminal
pnpm add @shak-hooks/usehooks
import.ts
import { useObjectState } from "@shak-hooks/usehooks";
Source: packages/react/src/useObjectState.ts

Signature

signature.ts
export function useObjectState<T extends object>(initialValue: T)

Parameters

NameTypeOptionalDefault
initialValueTNo-

Returns

unknown

Implementation

use-object-state.ts
1import { useState, useCallback } from "react";
2
3export function useObjectState<T>(initialValue: T) {
4 const [state, setState] = useState(initialValue);
5
6 const update = useCallback((partial: Partial<T>) => {
7 setState((prev) => ({ ...prev, ...partial }));
8 }, []);
9
10 return [state, update] as const;
11}

Advertisement

Google Ads

Usage

example.tsx
1import { useObjectState } from "@shak-hooks/usehooks";
2
3const result = useObjectState(undefined);
4// result: unknown
5// Use values directly (React state).

Let‘s do great work together

Empowering creators with free, high-performance AI, SEO, and developer tools. Join thousands of users optimizing their workflow with Shak-Tools.

Tools10+ Free
UsersGlobal

Stay in the loop

Join our newsletter for the latest AI tools and updates.

ShakTools
© 2025 Shaktools. All Rights Reserved.Privacy Policy