1.0.3 β€’ Published 10 months ago

@akash_deep_chitransh/react-mini-state v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

πŸ”Œ react-mini-state

A lightweight and optimized state management library for React, built with simplicity and performance in mind. Supports selectors to prevent unnecessary re-renders and works seamlessly with TypeScript.


πŸš€ Installation

npm install @akash_deep_chitransh/react-mini-state
# or
yarn add @akash_deep_chitransh/react-mini-state

🧠 Core APIs

This library exposes only two main APIs:

1. createStore(initialState)

Creates the global store.

import { createStore } from "react-mini-state";

const store = createStore({ count: 0 });

2. createUseStore(store)

Returns a custom hook (useStore) that subscribes to the store.

import { createUseStore } from "react-mini-state";

const useStore = createUseStore(store);

βš™οΈ Usage

βœ… Example: Counter

import React from "react";
import { createStore, createUseStore } from "react-mini-state";

const store = createStore({ count: 0 });
const useStore = createUseStore(store);

const increment = () =>
  store.setState((prev) => ({ ...prev, count: prev.count + 1 }));

const Counter = () => {
  const count = useStore((state) => state.count);

  return (
    <div>
      <p>{count}</p>
      <button onClick={increment}>Increment</button>
    </div>
  );
};

🎯 Features

  • βœ… Only two APIs β€” Easy to learn and use
  • ⚑ Optimized with selector β€” Components only re-render when the selected state changes
  • πŸ”„ Store mutation via setState
  • πŸ’™ TypeScript support out of the box
  • 🎣 Built using React’s useSyncExternalStore

πŸ“¦ TypeScript Support

You can define your store state type and enjoy full type inference:

type StoreState = { count: number };
const store = createStore<StoreState>({ count: 0 });

const useStore = createUseStore(store);

🀝 Contributing

If you'd like to contribute, feel free to fork the repo and open a pull request.


πŸ“„ License

MIT

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago