<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/react-forgot-to-add-something--vsvtnafcf" -->

---
title: React forgot to add something. | daily.dev
description: A new open-source library called native-state-react offers lightweight global state management for React, positioned as a drop-in alternative to Redux and...
canonical: https://daily.dev/posts/react-forgot-to-add-something--vsvtnafcf
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: React forgot to add something. | daily.dev
og:description: A new open-source library called native-state-react offers lightweight global state management for React, positioned as a drop-in alternative to Redux and...
og:url: https://daily.dev/posts/react-forgot-to-add-something--vsvtnafcf
og:image: https://api.daily.dev/og/posts/VSVtnAfcF.png
og:image:alt: React forgot to add something.
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# React forgot to add something.

**[The React Community](https://daily.dev/sources/the_react_community)** · [@sarathkalathil8](https://daily.dev/sarathkalathil8) · 4 min read · 2 upvotes · 1 comments

## Summary

A new open-source library called native-state-react offers lightweight global state management for React, positioned as a drop-in alternative to Redux and MobX. Built with just React's built-in hooks in a single 115-line file, it uses string path notation for state access via useNativeState and useNativeSelector hooks. The author highlights performance optimizations including pre-compiled path getters, path-targeted subscriptions with O(1) lookup, and microtask notification batching, claiming 10x improvements in state-setting speed and operations per second over unspecified alternatives.

## Content

It is a global state management. Now you are thinking "Why not React context or any others?". The answer is simple. People cannot use something which has less render control and difficult to use, React knows it and that's exactly the reason they say this

![image.png](https://media.daily.dev/image/upload/s--D5YLRgHW--/f_auto/v1788419764/ugc/content_8d7d4377-acd8-4a4b-8c8b-f054fe674952?_a=BAMAMicg0)

Thats why Redux still wins. But I really hate boilerplate code. Did RTK solved it? sorry, not for me . And, all other libraries make us write a lot of code. Mobx I liked, but decorators and multi store makes it tough.

Why don't I make a normal object , make it reactive and control the render to value level. yes, if one value changes, that value subscriptions will render, nothing else.

So I created [**native-state-react**](https://github.com/sarath263/native-state), uses just a couple of react hooks and just a single file. The entire library is a single file. React should have done this before.

The project started as an experiment to simplify the state and data, reduce boilerplate compared to Redux or Context API and a simple and local state feel for developers, while still offering predictable and scalable state handling. It means a lot coz philosophy of keeping React development closer to its native feel — minimal abstractions, maximum clarity.

Here is the github [link to the project. ](https://github.com/sarath263/native-state)See [benchmark .](https://github.com/user-attachments/assets/d1aab014-aa6f-4219-b95a-a2ad7fffe421)

Renders has been optimized to the extended levels available in eventloop engine.

**Pre-compiled path getters (compileGetter)**: Replaced slow loop-based object property drilldowns with optimized, static depth getter functions, avoiding array allocations and loop overhead on every render cycle.

**Path-targeted subscriptions**: Replaced the global subscriber set with a Map of paths to sets of listener callbacks. This ensures that updates to one slice of state only notify relevant subscribers, achieving $O(1)$ lookup for exact selector matches and avoiding unnecessary calculations for unrelated subscribers.

**Microtask notification batching (queueMicrotask)**: Implemented batched notifications so that rapid successive state updates (e.g. synchronous update loops) queue callbacks and trigger component updates/re-renders exactly once at the end of the tick.

## **Demo**

You can explore the package[ native-state-react on npm](https://www.npmjs.com/package/native-state-react). A demo is available in [Stack blitz here](https://stackblitz.com/edit/native-state-react?file=src%2FApp.jsx). The repo includes usage examples showing how to define state, update it, and consume it across components without complex setup.

## Usage

1. Wrap your app with the `<Root>` component at the top level, optionally providing the initial state.
2. Use `useNativeState` in your components to read and update global state.

### Use it almost like _useState_.. see below

in your component:

```
import { useNativeState } from 'native-state-react';

function App() {
  const [name, setName] = useNativeState('s.name', 'Andrew');

  const updateName = () => {
    setName("George");
  };

  return (
    <div>
      <p>Name: {name}</p>
      <button onClick={updateName}>Update Name</button>
    </div>
  );
}
```

#### See running [Demo Here](https://stackblitz.com/edit/native-state-react?file=src%2FApp.jsx)

## API

### `<Root>`

The root component that initializes the global state store.

- `initial`: (optional) Object - The initial state. Defaults to an empty object `{}`.
- `children`: (optional) React Nodes - Children to render inside `<Root>`.

### `useNativeState(pathString, initialVal)`

Hook to read and write a specific slice of the global state using string path notation.

- `pathString`: **String** - The path to select in the global state, starting with `'state'` or `'s'` (e.g. `'s.name'`, `'state.school.class'`, `'s.todos[0].title'`, `'state.school.class.student[21]'`).
- `initialVal`: (**optional**) Any - The value to initialize in the `pathString`. Note that if `pathString` is already initialized or has value set, it will NOT be updated/initilized again, you may cal set method to update the value.

Returns: `[value, setValue]`

- `value`: The current value at the specified path.
- `setValue`: Function to update the value of this specific path.

> [!WARNING]

> if `pathString` is `s.todos[0].title` , `s.todos[0]` must exist in the global state so that it can retrieve/set `title`

### `useNativeSelector(selectorFunction)`

A highly optimized read-only hook that subscribes to state slices. Components using this hook will re-render **only** when the selected slice changes. Internally utilizes React's modern `useSyncExternalStore` for tear-free rendering.

- `selectorFunction`: Function - A function that accepts the state and returns the selected slice (e.g. `s => s.name`).

Returns: `value`

- `value`: The read-only value of the selected state slice.

## BENCHMARK

Code used to run benchmark can be found in [benchmarks folder ](https://github.com/sarath263/native-state/tree/main/benchmark).

## Community discussion

Top comments from developers on daily.dev.

**@sonalikassa** · 1 upvotes

> It is really useful

## Similar posts on daily.dev

- [Untitled](https://daily.dev/posts/untitled-weezlgz6n) · SitePoint · 2 upvotes · 1 comments
- [React has changed, your Hooks should too](https://daily.dev/posts/react-has-changed-your-hooks-should-too-hokoxoemk) · Matt Smith · 38 upvotes · 5 comments
- [Issue \#484: The absolute state of 'state management' — React Status](https://daily.dev/posts/issue-484-the-absolute-state-of-state-management-react-status-un0zm9lqy) · React Status · 1 upvotes · 0 comments
- [Do we need state management libraries anymore?](https://daily.dev/posts/do-we-need-state-management-libraries-anymore--hihonpucg) · Neciu Dan · 4 upvotes · 1 comments

---

Tags: [#javascript](https://daily.dev/tags/javascript), [#react](https://daily.dev/tags/react), [#performance](https://daily.dev/tags/performance), [#redux](https://daily.dev/tags/redux)

[View this post on daily.dev](https://daily.dev/posts/react-forgot-to-add-something--vsvtnafcf)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"DiscussionForumPosting","mainEntityOfPage":"https://daily.dev/posts/react-forgot-to-add-something--vsvtnafcf","headline":"React forgot to add something.","text":"A new open-source library called native-state-react offers lightweight global state management for React, positioned as a drop-in alternative to Redux and MobX. Built with just React's built-in hooks in a single 115-line file, it uses string path notation for state access via useNativeState and useNativeSelector hooks. The author highlights performance optimizations including pre-compiled path getters, path-targeted subscriptions with O(1) lookup, and microtask notification batching, claiming 10x improvements in state-setting speed and operations per second over unspecified alternatives.","url":"https://daily.dev/posts/react-forgot-to-add-something--vsvtnafcf","datePublished":"2026-09-01T08:39:44.908Z","dateModified":"2026-10-28T10:04:20.430Z","author":{"@type":"Person","name":"Sharath","url":"https://daily.dev/sarathkalathil8","image":"https://lh3.googleusercontent.com/a/ACg8ocJ6AOa3zh1ZvJ8U2IfFddRVdbuAU4USpc2DYClIpSCTB3_bn_A=s96-c","interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"EndorseAction"},"userInteractionCount":110}},"image":"https://media.daily.dev/image/upload/s--glhkdrd_--/f_auto/v1790571317/posts/VSVtnAfcF?_a=BAMAMicg0","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":2},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":1}],"comment":[{"@type":"Comment","text":"It is really useful","datePublished":"2026-09-15T07:05:13.670Z","url":"https://daily.dev/posts/VSVtnAfcF#c-udsf2D5EH","author":{"@type":"Person","name":"Sonali Kassa","url":"https://daily.dev/sonalikassa","image":"https://lh3.googleusercontent.com/a/ACg8ocJMPwj84FsL4EhoEDcWizDe8KnKkvKhyB_XGVphhrggom4Kwl4=s96-c"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1}}],"isPartOf":{"@type":"WebPage","url":"https://daily.dev/squads/the_react_community","name":"The React Community"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"The React Community","item":"https://daily.dev/squads/the_react_community"},{"@type":"ListItem","position":3,"name":"React forgot to add something."}]}
```

