npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-hook-deep-state

v1.1.4

Published

![NPM Version](https://img.shields.io/npm/v/react-hook-deep-state) ![NPM Last Update](https://img.shields.io/npm/last-update/react-hook-deep-state) ![NPM Type Definitions](https://img.shields.io/npm/types/react-hook-deep-state) ![NPM Downloads](https://im

Readme

NPM Version NPM Last Update NPM Type Definitions NPM Downloads

React Hook Deep State

A small React hook for managing deeply nested state objects with type safety.

Table of Contents

Features

  • Deep State Management: Allows direct updates to deeply nested properties without modifying the rest of the state tree.
  • Intuitive API: Uses dot notation ("object.property.subproperty") to specify the property to update.
  • Flexible Updates: Supports both overriding and merging objects at any level of the state.

Installation

yarn add react-hook-deep-state

API

useDeepState<T>(initialState?: T)

Arguments:

  • initialState (optional): An initial state object of type T. Defaults to undefined if not provided.

Returns: A tuple [state, setDeepState]

  • state: The current state object of type T.
  • setDeepState: A function to update the state at a specific path.

setDeepState(value: StateValue<T, P, M>, path?: P, merge?: M)

Arguments:

  • value: The new value to set. The type of value depends on the path and merge parameters:
    • If merge is true, value can be a deep partial object for merging.
    • If merge is false, value must match the exact type of the property at the specified path.
  • path (optional): A string specifying the path to the property (e.g., "nested.key"). If omitted or "", the entire state is updated.
  • merge (optional): A boolean indicating whether to merge objects at the specified path. Defaults to true.

Examples

Usage

import React from 'react';
import { useDeepState } from 'react-hook-deep-state';

const App = () => {
  const [appState, setAppState] = useDeepState({
    user: {
      name: 'John Doe',
      address: {
        city: 'London',
        zip: '76321',
        country: 'GBR'
      },
      active: false,
      hobbies: []
    }
  });

  return (
    <div>
      <p>City: {appState.user.address.city}</p>
      <p>Active: {appState.user.active ? 'Yes' : 'No'}</p>

      <div>
        <label htmlFor='name'>Set Name:</label>
        <input
          type='text'
          id='name'
          name='name'
          value={appState.user.name}
          onInput={(e) => setAppState(e.currentTarget.value, 'user.name')}
        />
      </div>
    </div>
  );
};

export default App;

Updating the Entire State

setAppState(
  {
    user: {
      name: 'Jane Doe',
      address: {
        city: 'Berlin',
        zip: '12345',
        country: 'GER'
      },
      active: true,
      hobbies: ['Cycling', 'Swimming']
    }
  },
  '', // or undefined
  true // Merge by default, set to false to override current value
);

Update a Nested Property

setAppState('Tokyo', 'user.address.city');

Merge a Nested Object

setAppState({ zip: '94101', country: 'JAP' }, 'user.address', true);

Override a Nested Object

setAppState({ city: 'Canberra', zip: '90001', country: 'AUS' }, 'user.address', false);

Update a Nested Array

setAppState(['Skydiving', 'Hiking'], 'user.hobbies');

Running the Example Project

To see react-hook-deep-state in action, you can run the example project included in this repository.

  1. Install Dependencies: Navigate to the root of the project and install the dependencies:

    yarn install
  2. Navigate to the Example Folder: Move into the example folder:

    cd example
  3. Install Example Dependencies: Install the dependencies for the example project:

    yarn install
  4. Start the Development Server: Run the example project:

    yarn dev
  5. View in Browser: Open your browser and navigate to http://localhost:5173 to interact with the example project.

License

This project is licensed under the MIT License.


Disclaimer: This project is not affiliated with the Illuminati, any government, or other "deep state" entities. It is purely a tool for managing deeply nested state in React applications.