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

---
title: React forgot to add something. | daily.dev
description: A developer built native-state-react, a single-file (115 lines) global state management library for React using only built-in hooks like useSyncExternalStore....
canonical: https://daily.dev/posts/react-forgot-to-add-something--6nsyjehs7
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 developer built native-state-react, a single-file (115 lines) global state management library for React using only built-in hooks like useSyncExternalStore....
og:url: https://daily.dev/posts/react-forgot-to-add-something--6nsyjehs7
og:image: https://api.daily.dev/og/posts/6NsYjehS7.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.

**[Sharath](https://daily.dev/sources/9kpkddfa2fdhkolonvy8i)** · [@sarathkalathil8](https://daily.dev/sarathkalathil8) · 4 min read · 1 upvotes · 0 comments

## Summary

A developer built native-state-react, a single-file (115 lines) global state management library for React using only built-in hooks like useSyncExternalStore. It aims to replace Redux/Context API with a useState-like API via string path notation (e.g. 's.name'). The author claims 10x performance improvements from pre-compiled path getters, path-targeted subscriptions using a Map for O(1) lookups, and microtask-based notification batching. Includes a demo on StackBlitz and is published on npm.

## Content

It is a global state management. I know, Now you are thinking "Why not React context?". 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).

## Similar posts on daily.dev

- [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
- [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
- [Redux vs Zustand: Choosing the Right React State Manager](https://daily.dev/posts/redux-vs-zustand-choosing-the-right-react-state-manager-ru2kdxxkm) · Syncfusion · 8 upvotes · 2 comments
- [An Introduction to Zustand](https://daily.dev/posts/an-introduction-to-zustand-e9iwbl7jx) · Telerik · 1 upvotes · 0 comments
- [Zustand vs Redux Toolkit in 2026: Which State Management Library Should You Choose?](https://daily.dev/posts/zustand-vs-redux-toolkit-in-2026-which-state-management-library-should-you-choose--xwkkwdqv3) · Medium · 4 upvotes · 0 comments

---

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

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

```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--6nsyjehs7","headline":"React forgot to add something.","text":"A developer built native-state-react, a single-file (115 lines) global state management library for React using only built-in hooks like useSyncExternalStore. It aims to replace Redux/Context API with a useState-like API via string path notation (e.g. 's.name'). The author claims 10x performance improvements from pre-compiled path getters, path-targeted subscriptions using a Map for O(1) lookups, and microtask-based notification batching. Includes a demo on StackBlitz and is published on npm.","url":"https://daily.dev/posts/react-forgot-to-add-something--6nsyjehs7","datePublished":"2026-09-01T08:39:44.908Z","dateModified":"2026-09-13T20:52:07.254Z","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":140}},"interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"isPartOf":{"@type":"WebPage","url":"https://daily.dev/sources/9kpkddfa2fdhkolonvy8i","name":"Sharath"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Sharath","item":"https://daily.dev/sources/9kpkddfa2fdhkolonvy8i"},{"@type":"ListItem","position":3,"name":"React forgot to add something."}]}
```

