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 🙏

© 2026 – Pkg Stats / Ryan Hefner

usemergedstate

v2.0.0

Published

A replica of the React State Hook with the power of merging states

Readme

useMergedState

A replica of the React State Hook with the power of merging states.

What is React State Hook?

If you already know about React Hooks, you can skip this section and if not, continue reading.
The best way I think you can actually learn about Hooks is to watch this video(from react-conf) where Sophie Alpert and Dan Abramov explained in details what hooks are and why they exist. However, I would try and explain a bit here.
React State Hook is one of the many hooks that exist as feature proposal in React v16.7.0-alpha. Hooks are a new feature proposal that lets you use state and other React features without writing a class. With React State Hook(useState), you can make use of state in functional components(without writing a class).
This is a link to the documentation on Hooks.

The "limitation" of not being able to merge state

The useState hook exposes APIs that you can easily use to read and update the state created. However, the API for updating the state is actually going to replace the previous state with the new state.
Example:

const [userInfo, setUserInfo] = useState({ name: 'Dan', age: 26 });
// userInfo => { name: 'Dan', age: 26 }
setUserInfo({age: 27});
// userInfo => {age: 27}

The replacing behavior of useState is very well argued to be a befitting one on the State Hook documentation, however, I strongly believe that there are a lot of valid scenarios where developers would want to merge stuff to the state(without going the reducer way) as opposed to replacing the state.
If you are one of the folks that get limited with the replacing behavior of useState, then useMergedState is just for you.

useMergedState is Here to Help :sparkles:

useMergedState makes it possible to merge states(when they are objects).
If the previous state and the new state are both objects, useMergedState is going to merge the states(just like this.setState) but if they are not, it is simply going to replace the previous state with the new one(the default behavior of useState).

Installation

npm i usemergedstate

Code Example

Requiring the module:

const useMergedState = require('usemergedstate');

Merging State:

...
const [userInfo, setUserInfo] = useMergedState({ name: 'Dan', age: 26 });
// userInfo => { name: 'Dan', age: 26 }
setUserInfo({age: 27});
// userInfo => { name: 'Dan', age: 27 }
...

Roll back to default behavior:

...
const [name, setName] = useMergedState('Dan');
// name => 'Dan'
setName('Abramov');
// name => 'Abramov'
...