1.0.3 โ€ข Published 5 months ago

scrova v1.0.3

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

Scrova ๐Ÿš€

๐Ÿ”ฅ Scrova - The Next-Gen State Management Library for React

๐Ÿ“Œ Fast, Simple, Zero Boilerplate, and High-Performance State Management

๐Ÿš€ Features

โœ… Zero Boilerplate โ€“ Easier than Redux Toolkit
โœ… Global & Local State Management โ€“ Best combo of Zustand and Redux
โœ… Auto Reducers & Actions โ€“ Automatically handles reducers
โœ… Optimized Performance โ€“ No unnecessary re-renders
โœ… Works Inside & Outside React Components
โœ… Middleware & Async Handling Support

๐Ÿ“Œ Installation

npm install scrova

or

yarn add scrova

๐Ÿ“Œ Quick Example

import { useScrova, actions } from "scrova";

function Counter() {
  const [count, setCount] = useScrova("counter");

  return (
    <div>
      <h2>Counter: {count}</h2>
      <button onClick={() => setCount(actions.counter.increment())}>+1</button>
    </div>
  );
}

๐Ÿ“Œ Full Usage Guide

โœ… Step 1: Setup Global Store (Optional)

If you need a Global Store, define it here.

If only Local State is required, you can skip this step.

import { configureScrova } from "scrova";

// ๐ŸŸข Setup Global Store with Reducers
export const { useScrova, actions } = configureScrova({
  counter: {
    state: 0,
    reducers: {
      increment: (state) => state + 1,
      decrement: (state) => state - 1,
      incrementByAmount: (state, payload) => state + payload,
    },
  },
  user: {
    state: { name: "Guest", email: "" },
    reducers: {
      updateUser: (state, payload) => ({ ...state, ...payload }),
    },
  },
  theme: {
    state: "light",
    reducers: {
      toggleTheme: (state) => (state === "light" ? "dark" : "light"),
    },
  },
});

Now store is ready

โœ… Step 2: Using Scrova in Components

๐Ÿ”น Example 1: Counter with Global State

import { useScrova, actions } from "./store";

function Counter() {
  const [count, setCount] = useScrova("counter");

  return (
    <div>
      <h2>Counter: {count}</h2>
      <button onClick={() => setCount(actions.counter.increment())}>+1</button>
      <button onClick={() => setCount(actions.counter.decrement())}>-1</button>
      <button onClick={() => setCount(actions.counter.incrementByAmount(5))}>+5</button>
    </div>
  );
}

โœ” Now it's as simple as Zustand + Redux Toolkit! ๐Ÿš€

๐Ÿ”น Example 2: User Profile with Reducers

import { useScrova, actions } from "./store";

function UserProfile() {
  const [user, setUser] = useScrova("user");

  return (
    <div>
      <h2>Welcome, {user.name}</h2>
      <button onClick={() => setUser(actions.user.updateUser({ name: "John Doe" }))}>
        Change Name
      </button>
    </div>
  );
}

โœ” Now the User Profile will stay in sync across the entire app! ๐ŸŽฏ

๐Ÿ”น Example 3: Theme Toggle

import { useScrova, actions } from "./store";

function ThemeToggle() {
  const [theme, setTheme] = useScrova("theme");

  return (
    <button onClick={() => setTheme(actions.theme.toggleTheme())}>
      Toggle Theme ({theme})
    </button>
  );
}

โœ” Now the Theme will be controlled from a single state across the entire app! ๐ŸŽฏ

โœ… Step 3: Using Scrova for Local State (Like useState)

If you only need Local State, you can use useScrova() without configureScrova()!

import { useScrova } from "scrova";

function LocalCounter() {
  const [count, setCount] = useScrova(null, 0); // ๐Ÿ”ฅ Local State Mode

  return (
    <div>
      <h2>Local Counter: {count}</h2>
      <button onClick={() => setCount(count + 1)}>+1</button>
    </div>
  );
}

โœ” Now youโ€™ll get Zustand-like simple behavior, without any extra setup!

โœ… Step 4: Using Scrova Outside React (For APIs, Event Listeners)

Now you can use Scrova for Event Listeners and API Calls as well!

import { getScrovaState, setScrovaState } from "scrova";

// ๐Ÿ”น Event Listener เคธเฅ‡ State Access เค•เคฐเคจเคพ
document.addEventListener("keydown", (event) => {
  const theme = getScrovaState("theme");
  console.log(`Current Theme: ${theme}`);
});

// ๐Ÿ”น API Call เคฎเฅ‡เค‚ State Set เค•เคฐเคจเคพ
async function fetchUserData() {
  const res = await fetch("https://jsonplaceholder.typicode.com/users/1");
  const data = await res.json();
  setScrovaState("user", data);
}

โœ” Now Scrova is not just limited to Reactโ€”it will also work with APIs and Events! ๐Ÿš€

๐Ÿ“Œ Performance Optimization

Scrova is optimized for High Performance:

โœ” No Unnecessary Renders
โœ” Memory Efficient
โœ” Optimized for Large-Scale Apps

๐Ÿ“Œ Comparison: Redux Toolkit vs Zustand vs Scrova

FeatureRedux ToolkitZustandScrova ๐Ÿš€
Global State?โœ… Yesโœ… Yesโœ… Yes
Local State?โŒ Noโœ… Yesโœ… Yes
Slice-Based Structure?โœ… YesโŒ Noโœ… Yes (Auto)
Boilerplate Required?โŒ Too Muchโœ… Minimalโœ… Super Minimal
Reducer Functions Auto Generated?โŒ NoโŒ Noโœ… Yes
Middleware Support?โœ… Yesโœ… Yesโœ… Yes
Async Handling?โœ… Yes (Thunk)โŒ Noโœ… Yes (Built-in)
Works Outside React?โŒ NoโŒ Noโœ… Yes
Unnecessary Renders Removed?โŒ NoโŒ Noโœ… Yes
Reactivity Speed๐Ÿš€ Fastโšก Mediumโšกโšก Super Fast
Memory Usage๐Ÿ”ด High๐ŸŸก Medium๐ŸŸข Low
Instant State Updates?โŒ Noโœ… Yesโœ… Yes (Super Fast)
Enterprise-Level Performance?โŒ NoโŒ Noโœ… Yes

๐Ÿ“Œ Final Thoughts

๐Ÿ”ฅ Scrova is the best combo of Zustand + Redux Toolkit!

โœ… Global + Local State in One Hook
โœ… Zero Boilerplate
โœ… Works Inside & Outside React
โœ… High Performance & Optimized
โœ… Enterprise-Level State Management

๐Ÿ“Œ Contributors

๐ŸŽฏ Maintainer: Rohit Patel ๐Ÿ”— GitHub Repo: Scrova on GitHub

๐Ÿ“ข Pull Requests & Issues Welcome! ๐Ÿš€

๐Ÿš€ Ready to Use Scrova?

npm install scrova

๐Ÿ”ฅ Now Build Faster & Smarter with Scrova! ๐Ÿš€

1.0.3

5 months ago

1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago