
React encourages a very specific mental model: data flows top-down. Parents pass props to children,...
React encourages a very specific mental model: data flows top-down.
Parents pass props to children, state is lifted to common ancestors, and the UI updates predictably when that state changes. This works beautifully for most applications.
But large dashboards expose a limitation.
React assumes data flows like a tree.
Real-world dashboards behave more like a network.
Independent widgets need to communicate with each other without necessarily sharing a direct parent-child relationship. When the "React way" forces you to lift state near the root just so two distant components can talk, the render cycle can quickly become expensive.
Imagine a dashboard with:
A single filter change lifts state near the root.
Even if only two charts care about that filter, React still needs to walk through the component tree during reconciliation. The render cost grows with the size of the tree, not with the number of components that actually care about the change.
The result is a large render blast radius triggered by a tiny interaction.
This is where an Event-Driven Architecture can help.
Instead of forcing all communication through React state, components can broadcast events and subscribe to the ones they care about.
The browser already provides a perfect mechanism for this.
CustomEventThe DOM has had an event system for decades. We can leverage the native CustomEvent API to implement a lightweight client-side pub/sub event bus.
In simple terms:
React state is like passing a note through a classroom row by row.
Events are like making an announcement over a speaker.
Only the people who care will react.
This approach decouples components while keeping the UI responsive.
We start by defining an event map in TypeScript. This ensures that both publishers and subscribers agree on the structure of the event payload.
// eventBus.ts
type EventMap = {
FILTER_CHANGED: { category: string; value: string[] }
WIDGET_EXPANDED: { widgetId: string }
DATA_REFRESH_REQUESTED: void
}
export const EventBus = {
dispatch<K extends keyof EventMap>(event: K, detail?: EventMap[K]) {
const customEvent = new CustomEvent(event, { detail })
window.dispatchEvent(customEvent)
},
subscribe<K extends keyof EventMap>(
event: K,
callback: (data: EventMap[K]) => void,
) {
const handler = (e: Event) => callback((e as CustomEvent).detail)
window.addEventListener(event, handler)
return () => window.removeEventListener(event, handler)
},
}
This gives us two powerful guarantees:
If someone dispatches an incorrect payload, TypeScript will catch it before runtime.
A filter component deep inside a sidebar can broadcast an update without knowing which components depend on it.
// SidebarFilter.tsx
import { EventBus } from './eventBus'
export function SidebarFilter() {
const handleSelection = (category: string, value: string[]) => {
EventBus.dispatch('FILTER_CHANGED', { category, value })
}
return (
// filter UI
)
}
This action triggers no React re-renders by itself. It simply emits a browser event.
A chart widget somewhere else on the page can subscribe to that event and update its own local state.
// RevenueChartWidget.tsx
import { useEffect, useState } from 'react'
import { EventBus } from './eventBus'
export function RevenueChartWidget() {
const [filters, setFilters] = useState<string[]>([])
useEffect(() => {
const unsubscribe = EventBus.subscribe('FILTER_CHANGED', (data) => {
if (data.category === 'revenue') {
setFilters(data.value)
}
})
return () => unsubscribe()
}, [])
return (
// chart UI that re-renders only when needed
)
}
The key idea here is isolation.
Only the component that subscribes to the event updates. The rest of the dashboard remains untouched.
Instead of a root-level state update triggering a wide render pass, only interested components react.
Event-driven communication is not meant to replace React state entirely. React state is still the best tool when data directly drives UI structure.
However, events shine in specific scenarios:
When multiple charts or widgets need to react to global filters without re-rendering the surrounding layout.
A deep API utility can emit an event like SHOW_TOAST_SUCCESS without passing callback functions through multiple component layers.
If you're building micro-frontends, DOM events become a universal communication layer.
A React component can dispatch an event. A Vue component can subscribe. A plain JavaScript module can react.
The browser itself becomes the integration layer.
Event-driven systems introduce flexibility, but they also introduce complexity.
With React props and state, data flow is explicit.
Events introduce indirect communication:
Component A emits an event Component B reacts Component C updates later
Tracing that chain can be less obvious.
If every interaction becomes an event, the system can quickly resemble a message broker.
Too many events can create hidden coupling between parts of the application.
Like any architectural pattern, moderation matters.
Frameworks like React help us render UI efficiently.
But architecture is really about how information moves through the system.
Sometimes the cleanest solution is not more state, more context, or another store library. Sometimes the browser already provides the simplest tool.
By leveraging native DOM events, you can reduce coupling between components, limit unnecessary renders, and build dashboards that remain responsive even under heavy interaction.
React manages rendering.
Events manage communication.
Understanding when to use each is what separates component coding from frontend architecture.
gemmaI ported the whole Gemma-4 family — E2B, E4B, 12B, 31B, and the 26B-A4B MoE — to run on...
communityHey DEV, I'm Tobore. Let's actually connect. I've been on here for a while now, mostly writing and...
ai(yep, kinda clickbait, just for the funsies 😊) At the beginning of the year, I relaunched my...
aiMy laptop was sitting idle with the fan at full tilt. Nothing was running that I knew of. The culprit...
githubactionsI Built a Thing! TL;DR — Google Gemini-based Pull Request reviews and Issue Triaging for...
aiI've been hearing the word "harness" thrown around a lot lately. I assumed it just meant "the IDE" or...
Workflows from the Neura Market marketplace related to this DeepSeek resource