At Databrain, we've helped several dozen companies ship 1000+ customer-facing dashboards from fast growing startups that want to ship dashboards quickly to large cloud 100 enterprises that want robust, multi-tenant dashboards across various geographies globally. Here's what we've learned about building them.
React remains the dominant framework for building interactive dashboards in 2026. But the ecosystem has changed dramatically — React 19 introduced Server Components and the React Compiler, shadcn/ui replaced Material UI as the default component library, and TanStack Query became the standard for server state management.
If you're evaluating whether to build a dashboard from scratch or use a pre-built solution, start with our embedded analytics overview to understand the trade-offs.
This guide covers two paths:
- Build a custom React dashboard from scratch using modern 2026 patterns
- Embed production-ready dashboards in minutes using Databrain's web components
What you'll build:
- A React 19 dashboard with Vite and TypeScript
- Data fetching with TanStack Query and caching
- Authentication with JWT and role-based access control
- Real-time data updates
- Integration with Databrain for production analytics
Prerequisites:
- Node.js 20+ (Vite 8 requires 20.19+ or 22.12+) and npm 10+
- Basic React and TypeScript knowledge
Choosing Your Approach: Build vs. Embed vs. Template
Before writing code, the first decision is how to build your dashboard. Here's an honest comparison:
Approach Time to Ship Cost Flexibility Maintenance
When to build custom: You need a unique UI, you're learning React, or your dashboard is simple enough that a library adds unnecessary complexity.
When to use embedded analytics: You're building customer-facing dashboards for a SaaS product, need multi-tenancy, and can't afford 6 months of engineering on charts, drill-downs, and data pipelines. See our detailed embedded analytics vs. BI comparison to understand the differences.
90% of our customers tried building custom first, or using an open source solution like Apache Superset or Metabase, then switched to DataBrain. The maintenance cost of 20+ chart types, with complex drill-down and interactive dashboard behavior was the breaking point.
Step 1: Set Up React 19 with Vite and TypeScript
Vite is the standard build tool for React in 2026 — the React team officially recommends it as the primary alternative after deprecating Create React App in February 2025. Vite 8 (released March 2026) ships with Rolldown — a Rust-based bundler that replaced Rollup — delivering significantly faster builds.
Why React 19 Matters for Dashboards
React 19 shipped features specifically useful for data-heavy applications like dashboards:
- React Compiler — Stable since October 2025, the compiler automatically memoizes components and hooks — eliminating the need for manual useMemo/useCallback. New Vite, Next.js, and Expo projects ship with it enabled by default. Meta reports up to 12% faster initial loads and 2.5x faster interactions in production. For dashboards with dozens of components re-rendering on filter changes, this is a significant win.
- use() API — Read promises and context directly in render, simplifying data-fetching patterns.
- Server Components — Render data-heavy components on the server, reducing JavaScript shipped to the client. Server Components work best with frameworks like Next.js — for client-side Vite apps, you won't use these directly.
- Actions and useOptimistic — Handle form submissions (filter changes, date range selections) with automatic pending states.
For client-side dashboards built with Vite, you'll benefit from the React Compiler (enabled by default in new projects), the use() API, and Actions. Server Components require a framework like Next.js.
Step 2: Install Your Component Library and Data Layer
shadcn/ui for Dashboard Components
shadcn/ui has become the fastest-growing component library in React. The State of React 2024 survey showed it doubling from 20% to 42% usage in a single year, with 80% positivity — the highest of any library. By 2025, it was on the verge of overtaking MUI for the top spot. Its popularity is partly driven by AI coding tools (Cursor, v0, Lovable) that default to generating shadcn/ui code. It provides composable components you own and can customize.
TanStack Query for Server State
Every dashboard fetches data from APIs. TanStack Query (React Query) handles caching, background refetching, stale-while-revalidate, and error states — problems you'd otherwise solve manually with useState + useEffect.
Zustand for Client State
For client-side state like sidebar open/closed, selected filters, and dark mode preference, Zustand provides a minimal, performant store without the boilerplate of Redux.
Recharts for Data Visualization
For custom-built charts, Recharts is the most popular React charting library. It's composable, responsive, and works well with TypeScript.
Step 3: Build the Dashboard Layout
Create a responsive dashboard shell with a sidebar, header, and main content area using CSS Grid and shadcn/ui components.
src/components/DashboardLayout.tsx:
Step 4: Fetch and Display Data with TanStack Query
This is where dashboards differ from typical React apps. Dashboard data is server state — it comes from APIs, changes frequently, and multiple components often need the same data.
src/hooks/useDashboardData.ts:
src/components/MetricCards.tsx:
Notice that MetricCards and the RevenueChart below both call useDashboardMetrics(). TanStack Query deduplicates these - only one network request is made, and both components share the same cached data. This is the key architectural pattern: colocate data fetching with the component that needs it, and let the query layer handle deduplication and caching.
Also note the use of <Skeleton> instead of a spinner. Skeleton screens reduce perceived load time and prevent layout shift - both important for Core Web Vitals.
Step 5: Add Charts with Recharts
src/components/RevenueChart.tsx:
When Recharts Isn't Enough
Recharts handles common chart types well — line, bar, pie, area, scatter. But production dashboards often need more: Sankey diagrams, geo maps, Gantt charts, gauges, waterfall charts, pivot tables. For a broader comparison of options, see our guides on React chart libraries and JavaScript chart libraries.
At Databrain, we built a visualization engine spanning 48 chart types using ECharts for the 80% of charts where built-in interactivity saves months, and D3 for the 20% where pixel-level control matters. If your dashboard needs more than 5-6 chart types, building each one from scratch becomes the dominant cost — and it's where embedded analytics tools pay for themselves.
Step 6: Authentication and Role-Based Access Control
Production dashboards need authentication. Here's a minimal JWT pattern with React Router.
src/hooks/useAuth.ts:
src/components/PermissionGate.tsx:
For embedded dashboards, Databrain handles authentication through guest tokens with built-in row-level security — the token scopes what data a user can see at the database level, so you don't need to implement RBAC yourself.
Step 7: Performance Optimization
Dashboards are the most performance-sensitive pages in any application. Multiple charts, real-time data, and complex layouts compound to create performance challenges.
Code Splitting by Route
Lazy-load dashboard pages so users only download the JavaScript for the page they're viewing:
Core Web Vitals Targets
Metric Target Why It Matters
Practical tips for dashboards:
- Use <Skeleton> components to reserve space before data loads (prevents CLS)
- Set explicit height on chart containers (prevents layout shift)
- Use TanStack Query's staleTime to serve cached data instantly while refetching in the background
- The React Compiler handles memoization automatically — if you're on an older project without it, profile and add useMemo/useCallback where needed
Step 8: Real-Time Data Updates
For dashboards that need live data (operations dashboards, trading screens, monitoring), add WebSocket support:
This pattern updates TanStack Query's cache directly, so every component using useDashboardMetrics() re-renders with the new data automatically — no prop drilling, no manual state management.
Step 9: Putting It All Together
src/App.tsx:

Run it:
npm run dev
Visit http://localhost:5173 to see your dashboard.
Production Alternative: Embed Dashboards with Databrain
Building a custom dashboard teaches you React fundamentals. But production dashboards for SaaS products need significantly more than what's covered above: 48 chart types, drill-downs with cross-dashboard filtering, pivot tables, scheduled email reports, multi-tenant row-level security, CSV/PDF export, and theming that matches your brand.
BerryBox, an insure-tech startup, tried embedding Power BI into their SaaS app and hit roadblocks with multi-source data integration, risky deployments, and a steep DAX learning curve. They switched to Databrain and went from kickoff to production in 3 weeks — saving $250K and freeing up 6 months of engineering. Similarly, Freightify tried building analytics in-house before realizing the cost, then deployed Databrain in 1 week.
Databrain ships as two HTML custom elements — <dbn-dashboard> and <dbn-metric> — that work in React, Vue, Angular, or plain HTML. They render inside Shadow DOM for style isolation, so they won't conflict with your existing CSS. Under the hood, they're a full React analytics application bridged to Web Components using r2wc (React to Web Component).
Install the Plugin
Note: As of v0.16, the plugin's peer dependencies specify React 18. It works with React 19 in practice, but npm may show a peer dependency warning. You can use --legacy-peer-deps or an overrides field in package.json if needed.
Backend: Generate a Guest Token
Guest tokens scope what data a user can see. Your backend generates them — the token is never exposed to the client directly.
Node.js / Express:
The permissions object controls what embedded users can do - create metrics, customize layouts, download data, see the sidebar. This is how you implement RBAC without building it yourself.
Frontend: React Component
That's it. The <dbn-dashboard> element handles all 48 chart types, drill-downs with cross-dashboard filtering, theming, and real-time data — configured in Databrain's UI, not in your code.
Next.js (App Router)
For Next.js, the web component needs to run on the client. Create an API route for token generation and a client component for the embed:
app/api/guest-token/route.ts:
app/components/DatabrainEmbed.tsx:
The 'use client' directive is required because @databrainhq/plugin/web registers custom elements, which requires the DOM.
Customize the Theme
Match the embedded dashboard to your brand using the theme prop:
For full theming control including chart palettes, breakpoints, and metric layout columns, see the component API reference.
What You Get Out of the Box
Feature Custom Build With Databrain

React Dashboard Visualization Libraries Compared
If you're building charts from scratch, here's how the major libraries compare:
Library Bundle Size (gzipped) Chart Types TypeScript Best For
For more on how embedded visualization fits into your product, see our embedded visualization guide.
Deployment Checklist
Before shipping your dashboard to production:
- Replace demo API endpoints with production URLs
- Store tokens and API keys in environment variables (never commit .env)
- Enable code splitting for each dashboard page
- Set explicit heights on chart containers (prevents CLS)
- Test on mobile devices (responsive sidebar, touch interactions)
- Verify Core Web Vitals: LCP < 2.5s, INP < 200ms, CLS < 0.1
- Add error boundaries around chart components
- If using Databrain: whitelist your domain in Embed Settings
Next Steps
- Try Databrain free: Start building
- What is embedded analytics?: Complete overview
- Customer stories: See how BerryBox, Freightify, and SpotDraft ship dashboards
- Compare alternatives: Power BI Embedded alternatives
- npm package: @databrainhq/plugin
- Developer docs: docs.usedatabrain.com
Databrain is a purpose-built embedded analytics platform for SaaS companies. Start building or read the docs.



.png)
.png)



