scrova v1.0.3
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
Feature | Redux Toolkit | Zustand | Scrova ๐ |
---|---|---|---|
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! ๐