Stop Juggling Storage APIs! This One React Hook Rules Them All

Let’s be honest: as web developers, managing state is our bread and butter. But when it comes to persisting that state in the browser?

😡 Things get messy.

You’ve got localStorage, sessionStorage, IndexedDB… and if you’re feeling particularly adventurous, maybe you’ve even whispered the forbidden words:

“WebAssembly” and “SQLite” in a dark room πŸ•΅οΈβ€β™‚οΈ

🧠 What If It Were Easy?

What if you could have a perfectly organized, unified APIβ€” One hook to find everything you need, exactly when you need it?

Well, I got tired of the mess, so I built it.

Let’s break down the usual suspects:

πŸͺͺ localStorage & sessionStorage

βœ… Great for simple key-value pairs
❌ Synchronous (blocking)
❌ Tiny 5MB limit
❌ Only stores strings

Want to save an object?
Prepare for your daily JSON.stringify() + JSON.parse() rituals.
(-_-) zzZ


πŸ“¦ IndexedDB

βœ… Powerful and asynchronous
βœ… Can store complex data

But the API is… ceremonial.
It’s like trying to order a coffee by filing three forms in triplicate.
눈_눈


🧨SQLite + WebAssembly

The absolute mad lad’s choice.

You want a full, relational SQL database in the browser?
You want to harness the raw power of C++ compiled to WebAssembly?

Awesome! But the setup is not for the faint of heart.

Introducing πŸ”₯ React Omni Store

✨ Enter react-omni-store ✨

I created a set of beautiful hooks that wrap all this complexity in a warm, friendly, TypeScript-hugging blanket 🧣.

1️⃣ useStorage – The Dependable Butler πŸ§‘β€πŸ³

This is your go-to for everyday tasks.
Handles both localStorage and sessionStorage with the same simple API.
➑️ Automatically syncs state across tabs!


import { useStorage } from 'react-omni-store'

function UserGreeting() {
  // Remembers the name across browser sessions!
  const [name, setName] = useStorage('username', 'Guest');

  // Remembers only for this session!
  const [notes, setNotes] = useStorage('session-notes', '', 'sessionStorage');

  return (
     setName(e.target.value)}
    />
  );
}

No more JSON.parse() rituals.
✨ It. Just. Works. d(‒́ v β€’Μ€ d)

2️⃣ useIndexedDB – The Warehouse Manager πŸ—οΈ

When 5MB just won’t cut it.
useIndexedDB gives you a simple key-value API on top of the mighty IndexedDB, without all the setup pain.


import { useIndexedDB } from 'react-omni-store';

function ThemeSwitcher() {
  const [theme, setTheme] = useIndexedDB('ui-theme', 'light');

  return (
    <button onClick={() => setTheme(theme === 'light' ? 'dark' : 'light')}>
      Switch to {theme === 'light' ? 'Dark' : 'Light'} Mode
    </button>
  );
}

βœ… Asynchronous
βœ… Persistent
βœ… Smooth as butter 🧈

3️⃣ useSQLiteDB – The β€œWe Have a Hulk” Hook 🧠πŸ’₯

This is where it gets wild.
Have you ever been writing a React component and thought:

“You know what this needs? SQL JOINs.” 😏

With useSQLiteDB, you can spin up a full SQLite database in your browser using WebAssembly + sql.js, and run any SQL query you want!

Yes, you can now have foreign keys in your React state.
What a time to be alive. \ (β€’β—‘β€’) /


import { useSQLiteDB } from 'react-omni-store';

function Notes() {
  const { loading, error, execute, saveDatabase } = useSQLiteDB();

  const addNote = async (content) => {
    await execute("INSERT INTO notes (content) VALUES (?)", [content]);
    await saveDatabase(); // Persist the change
  };

  if (loading) return "Firing up the flux capacitor...";
  if (error) return "Oh no! Anyway...";

  return (
    // Your awesome, SQL-powered UI
  );
}

πŸ§ͺ Try the Demo App

I built a basic demo app to showcase everything:

βœ… To-do list
βœ… Theme switcher
βœ… Session-based greeting
βœ… SQLite-powered notes app

All living together in peace πŸ•ŠοΈ
All powered by react-omni-store.

πŸ“¦ Get Started

NPM:

bash
npm install react-omni-store

GitHub:
https://github.com/ADHILSHA/react-omni-store


β˜• Like It? Fuel Future Projects!

If react-omni-store saves you from storage-induced headaches,
Consider buying me a coffee!

Β 


Buy Me A Coffee

Β 

Happy coding, and may your browser storage forever be organized! πŸ§˜β€β™‚οΈπŸ’»πŸ§‘

Leave a Reply

Your email address will not be published. Required fields are marked *