Web TippsUse custom web fonts in Google Sheets charts(08.09.2026 um 17:05 Uhr)
Web TippsIntroducing the new 1Password App for Google Chat(08.09.2026 um 18:02 Uhr)
Web TippsUse custom web fonts in Google Sheets charts(08.09.2026 um 17:05 Uhr)
Web TippsIntroducing the new 1Password App for Google Chat(08.09.2026 um 18:02 Uhr)

🔧 Programmierung 🕛 vor 2 Monaten 3 Min Lesezeit
0

React State Management Without Redux or Zustand

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

React state management has a well-worn path: pick a library (Redux, Zustand, Jotai, MobX), define your store shape, write actions and reducers, connect components, wire up side effects.



It works. But for data that lives on the client — form state, cached API responses, user preferences — there's a simpler approach.



What if your database was the source of truth and your UI just reacted to changes?






The idea



Instead of fetching data from an API, storing it in state, and manually keeping things in sync, you query a local database directly. When data changes, the UI updates automatically. No reducers, no selectors, no cache invalidation.



ctrodb makes this pattern straightforward with three React hooks.






Setup



Wrap your app with DatabaseProvider:




CODE
import { Database } from "ctrodb"
import { DatabaseProvider } from "ctrodb/react"

const db = new Database({ name: "todos" })
await db.connect()

export default function App() {
return (
<DatabaseProvider db={db}>
<TodoApp />
</DatabaseProvider>
)
}









useQuery



useQuery runs a query and re-fetches whenever the collection changes:




CODE
import { useQuery } from "ctrodb/react"

function TodoList() {
const todos = useQuery("todos", (q) =>
q.sort({ createdAt: "desc" })
)

return (
<ul>
{todos.map((todo) => (
<li key={todo.id}>
<input
type="checkbox"
checked={todo.done}
onChange={() => todo.update({ done: !todo.done })}
/>
{todo.title}
</li>
))}
</ul>
)
}






The array contains Model instances. todo.update() and todo.delete() trigger re-fetches automatically.



Filter, sort, and paginate using the query builder callback:




CODE
const pending = useQuery("todos", (q) =>
q.where("done", false).sort({ createdAt: "desc" })
)

const page = useQuery("todos", (q) =>
q.sort({ createdAt: "desc" }).limit(10).offset(page * 10)
)









useDoc



Fetch a single record by ID:




CODE
import { useDoc } from "ctrodb/react"

function TodoDetail({ id }) {
const todo = useDoc("todos", id)
if (!todo) return <p>Loading...</p>
return <h2>{todo.title}</h2>
}









useMutation



Create, update, and delete with loading and error state tracking:




CODE
import { useMutation } from "ctrodb/react"

function AddTodo() {
const [title, setTitle] = useState("")
const { create, loading, error } = useMutation("todos")

async function handleSubmit(e) {
e.preventDefault()
await create({
title,
done: false,
createdAt: new Date().toISOString(),
})
setTitle("")
}

return (
<form onSubmit={handleSubmit}>
<input value={title} onChange={(e) => setTitle(e.target.value)} />
<button type="submit" disabled={loading || !title.trim()}>
{loading ? "Adding..." : "Add todo"}
</button>
{error && <p className="error">{error.message}</p>}
</form>
)
}









How reactivity works



ctrodb uses a Signal pattern. Every collection fires change events on create, update, and delete. The database has a global signal too.




CODE
const unsubscribe = db.on((event) => {
console.log(`${event.type} on ${event.collection}#${event.recordId}`)
})






useQuery subscribes to the database signal, checks if the event's collection matches, and re-fetches. That's the entire reactivity chain — no virtual DOM diffing, no selector memoization, no middleware.






What this replaces



I used to reach for Redux or Zustand for every app that needed shared state. Now I reach for them less and less. If the data can live in IndexedDB, it lives in the database. The React hooks handle the rest.



If you're curious, ctrodb is open source. Try the playground at .

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
3 Quellen
Use custom web fonts in Google Sheets charts
2 Quellen
Introducing the new 1Password App for Google Chat
1 Quelle
Context-aware access controls are available for Gemini Enterprise in the Admin console
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten React State Management Without Redux or Zustand

Thematisch verwandte Begriffe: React, State, Management, Without · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...