Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
YouTube Security VideosAndroid Police: Samsung is smashing records! #shorts #tech #phones(21.09.2026 um 13:55 Uhr)
YouTube Security Videosheise & c't: Bundesnetzagentur wollte diesen Futterautomaten verbieten(21.09.2026 um 13:53 Uhr)
YouTube Security VideosNeil Patel: Your Google Traffic Isn't An Asset It's A Loan #shorts(21.09.2026 um 14:05 Uhr)
Windows Tipps & SecurityF-14 A Tomcat Top Gun endlich als Revell Klemmbausteinmodell erhältlich(21.09.2026 um 14:27 Uhr)
Sichere ProgrammierungShow the Hand-Back Sample Before Approving an Agent Score(21.09.2026 um 14:15 Uhr)
Sichere ProgrammierungHybrid retrieval in one Postgres query: RRF over tsvector + pgvector(21.09.2026 um 14:15 Uhr)
YouTube Security VideosAndroid Police: Samsung is smashing records! #shorts #tech #phones(21.09.2026 um 13:55 Uhr)
YouTube Security Videosheise & c't: Bundesnetzagentur wollte diesen Futterautomaten verbieten(21.09.2026 um 13:53 Uhr)
YouTube Security VideosNeil Patel: Your Google Traffic Isn't An Asset It's A Loan #shorts(21.09.2026 um 14:05 Uhr)
Windows Tipps & SecurityF-14 A Tomcat Top Gun endlich als Revell Klemmbausteinmodell erhältlich(21.09.2026 um 14:27 Uhr)
Sichere ProgrammierungShow the Hand-Back Sample Before Approving an Agent Score(21.09.2026 um 14:15 Uhr)
Sichere ProgrammierungHybrid retrieval in one Postgres query: RRF over tsvector + pgvector(21.09.2026 um 14:15 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

Understanding atomFamily in Recoil with a Todo Example

When building complex React applications, we often deal with multiple instances of similar pieces of state. Managing each one separately with individual atoms can quickly become messy and repetitive. Recoil provides a powerful utility…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

When building complex React applications, we often deal with multiple instances of similar pieces of state. Managing each one separately with individual atoms can quickly become messy and repetitive. Recoil provides a powerful utility called atomFamily to solve this problem.



In this article, we’ll break down what atomFamily is, why it’s useful, and how it works in the context of a Todo app.









What is atomFamily?



atomFamily is a factory function that allows us to create parameterized atoms.




  • Instead of writing separate atoms for each todo, we can create one family of atoms.

  • Each atom inside the family is uniquely identified by its parameter (like an id).

  • This makes managing dynamic state instances (e.g., multiple todos, users, or chat rooms) simple and scalable.









Example Code Walkthrough



Let’s break down your provided example.






1. Defining the Atom Family






import { atomFamily } from "recoil";
import { TODOS } from "./todos";

export const todosAtomFamily = atomFamily({
key: "todosAtomFamily",
default: (id) => {
return TODOS.find((todo) => todo.id == id);
},
});








  • atomFamily creates a group of atoms for todos.

  • Each atom is accessed using todosAtomFamily(id).

  • The default value depends on the given id, pulling data from the static TODOS array.



This way, each id corresponds to a unique atom.









2. Using Atoms in Components






function Todo({ id }) {
const todo = useRecoilValue(todosAtomFamily(id));
return (
<>
{todo.title}
{todo.description}
<br />
</>
);
}








  • useRecoilValue(todosAtomFamily(id)) retrieves the specific todo state.

  • Each Todo component renders the title and description for its assigned id.









3. Updating State






function UpdatedTodo() {
const updateTodo = useSetRecoilState(todosAtomFamily(2));

useEffect(() => {
setTimeout(() => {
updateTodo({
id: "2",
title: "I can change anything",
description: "I am safal",
});
}, 2000);
}, []);

return <div>Hello</div>;
}








  • useSetRecoilState(todosAtomFamily(2)) gives us a setter for the todo with id = 2.

  • After 2 seconds, the todo is updated with a new title and description.

  • Because all components using todosAtomFamily(2) share the same state, they re-render automatically with updated values.









4. Main Application






function App() {
return (
<RecoilRoot>
<Todo id={1} />
<Todo id={2} />
<Todo id={2} />
<Todo id={2} />
<Todo id={2} />
<Todo id={2} />
<UpdatedTodo />
</RecoilRoot>
);
}







  • Multiple <Todo id={2} /> components all subscribe to the same state (todosAtomFamily(2)).

  • When UpdatedTodo modifies that state, all instances of id=2 automatically update.









Key Benefits of Using atomFamily



Avoids repetition – no need to manually define separate atoms for each todo.

Dynamic state – you can create atoms on-the-fly using parameters (like id).

Shared updates – if multiple components reference the same atom, updating it in one place updates all.

Scalable – great for managing lists, collections, or items fetched from APIs.









When to Use atomFamily?




  • Managing state for items with unique identifiers (todos, users, products, etc.).

  • Creating multiple instances of the same kind of state dynamically.

  • Sharing state across different components that depend on the same key.









Final Thoughts



Recoil’s atomFamily is one of the most powerful features when working with lists of dynamic data. In this todo example, you’ve seen how easy it becomes to create, read, and update multiple todo items without duplicating state logic.



If your app needs per-item state management, atomFamily should be your go-to tool.

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Understanding atomFamily in Recoil with a Todo Example

Thematisch verwandte Begriffe: Understanding, atomFamily, Recoil, with · 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 ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-94097 | A vulnerability was determined in Netcore NBR200V2 1.3.241127.071246. Th…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick