Building A Dynamic Dashboard with gluestack-ui and esm.sh

May 9, 2024

Building A Dynamic Dashboard with gluestack-ui and esm.sh

In this tutorial, we take a look into how gluestack-ui and esm.sh help simplify the process of creating dynamic and functional dashboards.

Creating dynamic dashboards that are both functional and visually appealing is a common challenge. Leveraging tools like gluestack-ui and esm.sh can significantly streamline this process, offering a powerful combination of UI components and efficient module loading.

Throughout this tutorial, we cover essential steps, from project setup to widget rendering, demonstrating how these tools can work in tandem to enhance the development process.

Dynamic Dashboards


What is gluestack-ui?

gluestack-ui is a universal UI library that provides optionally styled and accessible components. It is designed to be easy to use and integrate into existing projects, and it provides a consistent design language across different platforms. gluestack-ui is not a direct replacement for React Native Web, but it builds upon its components to provide additional features and performance improvements.


What is esm.sh?

esm.sh is a fast, smart, and global CDN for modern (ES2015+) web development. It supports bare import specifiers, trailing slashes in import URLs, and a special format for import URLs that allows the use of query parameters with trailing slashes. It also provides a CLI script for managing imports with import maps in Deno and Node/Bun.

The application will have a widget list from where you can drag and drop widgets in the canvas and it will use esm.sh to build on the browser and render the widget.

In this tutorial, we will cover the following:

  • Setting up the project
  • Creating the UI
  • Adding esm.sh
  • Dynamic import of modules
  • Rendering the module


Setting Up the Project

To create a new project, run the following command:

   npm create gluestack

◇  What would you like to build?
│  Web app
◇  What is the  name  of your application?
│  dynamic-dashboard
◇  Would you like to use App Router?
│  Yes

The app with gluestack-ui is created.


Creating the UI

We create a basic UI with the widget list consisting of the list of widget and a drop area where the widgets are dropped. We will create a widget render component that will render the widget once it is dropped.


The ESM Code

Create a widget.js file on the public folder and include the following code:

import build from '<https://esm.sh/build>'
export async function loadLineChartComponent() {
  const ret = await build({
    dependencies: {
      preact: '^10.13.2',
      'preact-render-to-string': '^6.0.2'
    },
    source: `
    /* @jsx h */
    import { h } from "preact";
    export function render(): string {
      return <h1>Widget 1</h1>
    }
  `,
    types: `
    export function render(): string;
  `
  })
  const { render } = await import(ret.url)
  return render
}
// to make it accessible through our project we add it to the window object.
window.widget1 = loadLineChartComponent


Dynamic Import When the Widget is Dragged and Dropped

The following code is used to render the widget once it is dropped:

export const WidgetRender = forwardRef((props: WidgetRenderProps, ref) => {
  const [WidgetComponent, setWidgetComponent] = useState(null)
  useEffect(() => {
    const script = document.createElement('script')
    script.src = props.widget.id
    script.async = true
    script.type = 'module'

    script.onload = () => {
      if (window[props.widget.widgetFunction]) {
        window[props.widget.widgetFunction]()
          .then((x) => {
            setWidgetComponent(x())
          })
          .catch((e) => {
            console.log('e', e)
          })
      }
    }

    document.body.appendChild(script)
    return () => {
      document.body.removeChild(script)
    }
  }, [])

  const { type, props: customprops } = WidgetComponent || {}

  return (
    <div ref={ref} {...props}>
      <Suspense fallback={<>Loading</>}>
        {WidgetComponent ? (
          <Box h='100%' w='100%' bgColor='$primary500'>
            {React.createElement(type, customprops)}
          </Box>
        ) : null}
      </Suspense>
    </div>
  )
})
Hire Us Form


Summing Up

Building a dynamic dashboard using gluestack-ui and esm.sh represents a modern approach to web development, emphasizing efficiency and flexibility. By harnessing the capabilities of gluestack-ui's intuitive UI components and esm.sh's dynamic module loading, developers can create interactive dashboards that adapt to evolving requirements.

Subscribe to Our Newsletter

More from the engineering frontline.

Dive deep into our research and insights on design, development, and the impact of various trends to businesses.
Insight
From Test Failure to Root Cause: Building an AI-Assisted Playwright Failure Analysis Pipeline
Oct 9, 2026

From Test Failure to Root Cause: Building an AI-Assisted Playwright Failure Analysis Pipeline

This blog explains how an AI-assisted Playwright pipeline can analyze test failure evidence, identify probable root causes, and support human-validated debugging.

Insight
The Model Context Protocol: From First Call to Production
Oct 8, 2026

The Model Context Protocol: From First Call to Production

This blog explains how Model Context Protocol (MCP) works, from tool discovery and execution to OAuth authorization, security controls, and production deployment.

Insight
Stop Automating Everything: A Balanced Quality Engineering Approach to Testing
Oct 8, 2026

Stop Automating Everything: A Balanced Quality Engineering Approach to Testing

Balanced quality engineering places automation, API testing, exploratory work, and AI where each gives the most value, so teams ship faster without trading away user-perceived quality.

Insight
From Rolling Deployments to Zero-Downtime Releases
Oct 6, 2026

From Rolling Deployments to Zero-Downtime Releases

This blog explains how Blue-Green deployment helps reduce downtime in online banking releases through traffic switching, pod readiness, static-resource versioning, and rapid rollback.

Insight
The Deprecation Notice Nobody Reads
Oct 5, 2026

The Deprecation Notice Nobody Reads

This blog explains why API deprecation notices often fail and how staged retirement, telemetry, brownouts, and scheduled enforcement can make API migrations more controlled and predictable.

Insight
Why Legacy Systems Make Business Growth More Expensive: Navigate A Smarter Path to Legacy Modernization
Sep 23, 2026

Why Legacy Systems Make Business Growth More Expensive: Navigate A Smarter Path to Legacy Modernization

Learn how legacy systems make business growth more expensive and how edge-first modernization can remove constraints without replacing the existing system.

Insight
SSO, Audit Logs and RBAC: The Enterprise Features AI Prototyping Tools Do Not Cover | Sarika Gautam
Sep 23, 2026

SSO, Audit Logs and RBAC: The Enterprise Features AI Prototyping Tools Do Not Cover | Sarika Gautam

Why AI-generated prototypes fail enterprise review: the context behind SSO, the cost of skipping audit logs, and how role explosion makes RBAC a product of its own.

Footer

The Right Conversation Can

Save You Six Months.

Book a Call