Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
Sichere ProgrammierungTCP vs UDP: The Two Ways to Move Data, and Why Neither Is "Better"(21.09.2026 um 09:31 Uhr)
Sichere ProgrammierungBukan Sekadar Variabel, Tapi Nyawa dari Aplikasi Kamu! 🚀(21.09.2026 um 09:36 Uhr)
Sichere ProgrammierungAI voice agent for customer service: what stops callers hanging up?(21.09.2026 um 09:42 Uhr)
Sichere ProgrammierungReading a small model's confidence instead of its prose(21.09.2026 um 09:47 Uhr)
Sichere ProgrammierungTCP vs UDP: The Two Ways to Move Data, and Why Neither Is "Better"(21.09.2026 um 09:31 Uhr)
Sichere ProgrammierungBukan Sekadar Variabel, Tapi Nyawa dari Aplikasi Kamu! 🚀(21.09.2026 um 09:36 Uhr)
Sichere ProgrammierungAI voice agent for customer service: what stops callers hanging up?(21.09.2026 um 09:42 Uhr)
Sichere ProgrammierungReading a small model's confidence instead of its prose(21.09.2026 um 09:47 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

React Native notification center with xState v5

TL;DR If you just want to see the code, it is here. And this is the PR with the latest changes that are discussed in the post. Disclaimer For this example we will be using React Native Paper. It greatly helps with design and…

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




TL;DR



If you just want to see the code, it is here. And this is the PR with the latest changes that are discussed in the post.






Disclaimer



For this example we will be using React Native Paper. It greatly helps with design and saves development time. It might take you some extra steps to integrate, but it is easy and intuitive to use.






Background



After setting the basics of the app architecture, we can now continue with the introduction of other important functionalities. In this post we will have a look at how we handle any sort of in-app notifications/messages that we want to display to the user.



While working on our application, we observed that the ways of providng the user with proper visual feedback grow. To manage all our snackbars/modals/dialogs/banners, we decided to move their orchestration in a separate machine.






Notification Center



The notificationCenter machine is spawned on project initilization. Its reference is kept at root level so that it is be available for all spawned children to communicate with.

For this example we are only handling two types of notification feedbacks but it is easily extendable.




export const notificationCenterMachine = setup({
types: {
context: {} as {
snackbar: {
type: Extract<NotificationType, "snackbar">;
message: string;
severity: NotificationSeverity;
};
modal: {
type: Extract<NotificationType, "modal">;
title: string;
message: string;
};
},
events: {} as
| {
type: "NOTIFY";
notification: Notification;
}
| { type: "OPEN_SNACKBAR" }
| { type: "OPEN_MODAL" }
| { type: "CLOSE" },
},
}).createMachine({
context: {
snackbar: {
type: "snackbar",
message: "",
severity: "error",
},
modal: { type: "modal", message: "", title: "" },
},
id: "notification",
initial: "idle",
on: {
NOTIFY: {
actions: enqueueActions(({ event, enqueue }) => {
if (event.notification.type === "snackbar") {
enqueue.assign({ snackbar: event.notification });
enqueue.raise({ type: "OPEN_SNACKBAR" });
}

if (event.notification.type === "modal") {
enqueue.assign({ modal: event.notification });
enqueue.raise({ type: "OPEN_MODAL" });
}
}),
},
OPEN_SNACKBAR: {
target: ".snackbar.open",
},
OPEN_MODAL: {
target: ".modal.open",
},
},
type: "parallel",
states: {
idle: {},
snackbar: {
initial: "closed",
states: { open: { on: { CLOSE: { target: "closed" } } }, closed: {} },
},
modal: {
initial: "closed",
states: { open: { on: { CLOSE: { target: "closed" } } }, closed: {} },
},
},
});






The machine listens for the NOTIFY event, which based on the type of notification it receives, keeps the latest notification in the context. The notification is then read and displayed/closed by the corresponding component.






Feedback



There are two components that are subscribed to the notificationCenter reference - NotificationSnackbar and NotificationModal. They expect the refNotificationCenter as prop and based on the state decide whether to show the notification. The components are rendered outside of the so that they are available to all application screens.




export function Navigation() {
const { send, state } = useApp();

return (
<NavigationContainer
onReady={() => {
send({ type: "START_APP" });
}}
ref={navigationRef}
>
<RootNavigator />
{state.context.refNotificationCenter && (
<>
<NotificationSnackbar actor={state.context.refNotificationCenter} />
<NotificationModal actor={state.context.refNotificationCenter} />
</>
)}
</NavigationContainer>
);
}









Communication



The issue with this approach in xState v4 was that we couldn't predict how deep our actor tree would grow. Sending events between siblings and grandparents in was not straightforward. In case we needed to send an event through several levels of hierarchy, each actor should act as a middleman and resend the event to its parent until the final goal is reached.



The new actor system makes it a lot easier with the receptionist pattern. XState creates implicitly a system, which now gives us a chance to reach out the notification center by sending single event from any child machine.




sendToNotificationCenter: sendTo(
({ system }) => {
return system.get("notificationCenter");
},
(_, params: { notification: Notification }) => {
return {
type: "NOTIFY",
notification: params.notification,
};
},
)






Unfortunately, similarly to sendParent, we loose our type-safety. As a workaround, I'm using a simple util to guarantee that the notification is in the right format:




export function getNotificationCenterEvent(
{},
params: { notification: Notification },
) {
return {
type: "NOTIFY",
notification: params.notification,
};
}









sendToNotificationCenter: sendTo(({ system }) => {
return system.get("notificationCenter");
}, getNotificationCenterEvent)






After having the action registered with the setup method, we can simply call it with:




{
type: "sendToNotificationCenter",
params: ({ event }) => {
return {
notification: {
type: "snackbar",
severity: "success",
message: `You've added an item with id ${event.output.item.id}.`,
},
};
},
}






You can check the end results by opening the List screen and play around with the new functionalities.



screenshot 1



screenshot 2



screenshot 3






Conclusion



Leaving all the advantages aside, I was expecting better type-safety with the sendTo action in combination with the system.get() method. Currently, the situation is similar to what we can achieve with sendParent. However, the flexibility in communication provided by the receptionist pattern enhances the developer experience.

Secondly, this is the first time I've experimented with enqueueActions() and I'm beginning to see its potential. It is different from what I've been used to, but it can greatly simplify state machines.

Next, I plan to implement a registration wizard/funnel.

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten React Native notification center with xState v5

Thematisch verwandte Begriffe: React, Native, notification, center · 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-94030 | A security vulnerability has been detected in SerenityOS up to 3d83e4509…
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