@opentf/react-state
TypeScript icon, indicating that this package has built-in type declarations

0.16.0 • Public • Published

 OPEN TECH FOUNDATION

React State

Build

A global state manager for React.

Features

  • Simple API
  • Mutable State Updates
  • No Context Providers
  • Auto Shallow Diff Computed Props
  • TypeScript Support

Installation

npm install @opentf/react-state
yarn add @opentf/react-state
pnpm add @opentf/react-state
bun add @opentf/react-state

Usage

import { create } from '@opentf/react-state';

const { useAppState, setAppState, api } = create({ count: 0 });

api.subscribe(console.log);

export default function App() {
  const count = useAppState((s) => s.count);

  return (
    <>
      <p>Count: {count}</p>
      <button
        onClick={() =>
          setAppState((s) => {
            s.count++;
          })
        }
      >
        Increment
      </button>
    </>
  );
}

Related

License

Copyright (c) 2021, Thanga Ganapathy (MIT License).

Package Sidebar

Install

npm i @opentf/react-state

Weekly Downloads

3

Version

0.16.0

License

MIT

Unpacked Size

15.4 kB

Total Files

9

Last publish

Collaborators

  • ganapathy