React Mosaic Component: Build Resizable Tiling Layouts (v7)

A dispatch screen with four panels people can resize and shuffle sounds like weeks of work, but the React Mosaic component handles it with one tree object.

Install react-mosaic-component, import its CSS, then render <Mosaic> inside a parent with a real height. Pass a layout tree as initialValue and a renderTile function that wraps each panel in <MosaicWindow>:

<Mosaic<string>
  initialValue={{ type: "split", direction: "row", children: ["a", "b"] }}
  renderTile={(id, path) => <MosaicWindow path={path} title={id}>{id}</MosaicWindow>}
/>

That gives two side-by-side windows with a draggable divider. In this tutorial, I’ll build a React Mosaic component dashboard for a Chicago delivery company, then save its layout, drag windows around and add tabs.

How to Install react-mosaic-component in a React App

Start from a Vite React + TypeScript app (set up a React environment if you don’t have one) and add the package:

npm create vite@latest dispatch -- --template react-ts
cd dispatch
npm install react-mosaic-component

I ran everything below on react-mosaic-component 7.2.1, React 19.3, TypeScript 7.0.2 and Vite 8.3.

Every example renders the same four panels from src/panels.tsx:

import "./panels.css";

export type PanelId = "orders" | "drivers" | "revenue" | "alerts";

export const TITLES: Record<PanelId, string> = {
  orders: "Open Orders",
  drivers: "Drivers",
  revenue: "Revenue",
  alerts: "Alerts",
};

const ROWS: Record<PanelId, string[]> = {
  orders: ["#1042 Lincoln Park  $86.40", "#1043 Wicker Park  $42.15",
    "#1044 Hyde Park  $129.99"],
  drivers: ["Maria Lopez - 6 stops", "Tyler Brooks - 4 stops"],
  revenue: ["Today: $4,812.75", "This week: $27,390.20"],
  alerts: ["I-90 slow near O'Hare", "Van 12 due for service"],
};

export function PanelBody({ id }: { id: PanelId }) {
  return (
    <ul className="rows">
      {ROWS[id].map((r) => <li key={r}>{r}</li>)}
    </ul>
  );
}

Important: the default mosaic-blueprint-theme class needs Blueprint’s CSS for its button icons, and Blueprint 5 stops at React 18. Without it you get empty buttons, so pass your own class, such as className="dispatch", and style the plain theme. The key rules in panels.css:

.dispatch .mosaic-window-toolbar { background: #1e3a5f; color: #fff; }
.dispatch .mosaic-default-control { margin-right: 6px; padding: 2px 8px;
  border: 0; border-radius: 4px; background: #2f6fb0; color: #fff; }

Basic React Mosaic Example with Two Windows

The first layout puts Open Orders next to Drivers. renderTile runs once per panel id, and you pass its path straight to MosaicWindow (typing it as Mosaic<PanelId> works like any typed React component):

import { Mosaic, MosaicWindow } from "react-mosaic-component";
import "react-mosaic-component/react-mosaic-component.css";
import { PanelBody, TITLES } from "./panels";
import type { PanelId } from "./panels";

export default function App() {
  return (
    <div style={{ height: "100vh" }}>
      <Mosaic<PanelId>
        className="dispatch"
        initialValue={{
          type: "split",
          direction: "row",
          children: ["orders", "drivers"],
        }}
        renderTile={(id, path) => (
          <MosaicWindow<PanelId> path={path} title={TITLES[id]}>
            <PanelBody id={id} />
          </MosaicWindow>
        )}
      />
    </div>
  );
}
React Mosaic component with two windows, Open Orders and Drivers, side by side in Microsoft Edge
Two Mosaic windows with title bars and a divider you can drag.
VS Code with the React Mosaic App.tsx open and tsc plus the Vite dev server running in the terminal
The same App.tsx in VS Code: tsc passes and Vite serves it.

The wrapper’s height: 100vh matters. Mosaic fills its parent, so a parent with no height renders a blank page.

How Does the React Mosaic Layout Tree Work?

A v7 layout is an n-ary tree. A leaf is just a panel id; a split node has a direction, any number of children and optional splitPercentages that add up to 100. Here, Orders takes 40% and the right side stacks Drivers over Revenue:

const layout: MosaicNode<PanelId> = {
  type: "split",
  direction: "row",
  splitPercentages: [40, 60],
  children: [
    "orders",
    {
      type: "split",
      direction: "column",
      children: ["drivers", "revenue"],
    },
  ],
};

I logged getLeaves(layout) to confirm the panel order:

leaves: orders, drivers, revenue
React Mosaic nested layout: Open Orders on the left at 40 percent, Drivers stacked above Revenue on the right
A row split holding a column split: three windows from one tree.

"row" means side by side and "column" means stacked. Keys must be unique, much like keys in a React tree view.

Save the React Mosaic Layout with onChange and onRelease

To keep a user’s layout, switch to controlled mode: value plus onChange. onChange fires on every frame of a resize, so save in onRelease, which fires once per finished drag (both are ordinary React event handlers):

const KEY = "dispatch-layout";

function loadLayout(): MosaicNode<PanelId> | null {
  const saved = localStorage.getItem(KEY);
  return saved ? JSON.parse(saved) : layout;
}

export default function App() {
  const [tree, setTree] = useState(loadLayout);

  function save(next: MosaicNode<PanelId> | null) {
    localStorage.setItem(KEY, JSON.stringify(next));
    console.log("saved:", getLeaves(next).join(", "));
  }

  return (
    <div style={{ height: "100vh" }}>
      <Mosaic<PanelId>
        className="dispatch"
        value={tree}
        onChange={setTree}
        onRelease={(next, meta) => {
          console.log("release:", meta?.type);
          save(next);
        }}
        renderTile={/* same as before */}
      />
    </div>
  );
}

Drag the bar between Drivers and Revenue up and you’ll see this (my real mouse drag):

release: resize
saved: orders, drivers, revenue
React Mosaic layout after dragging the divider between Drivers and Revenue upward, saved to localStorage
Drivers now takes about 33% of the right column.

The stored tree now holds splitPercentages of about 33 and 67 for that column, so the layout comes back on the next visit.

Drag a Window to Rearrange the Mosaic

Dragging is built in: grab a title bar and drop it on the edge of another window. Mosaic uses react-dnd’s HTML5 backend, so it works without the extra setup a React drag and drop component needs.

Same controlled app; I dragged the Revenue title bar onto the bottom edge of Open Orders:

release: drop
saved: orders, revenue, drivers
React Mosaic after dragging the Revenue window below Open Orders, with Drivers filling the right side
Revenue moved under Open Orders, and Drivers took the whole right side.

Add Tabs and Custom Toolbar Buttons in React Mosaic

A tabs node groups panels in one spot. toolbarControls replaces the default buttons, here with only Expand and Close:

const layout: MosaicNode<PanelId> = {
  type: "split",
  direction: "row",
  children: [
    "orders",
    {
      type: "split",
      direction: "column",
      children: [
        "drivers",
        { type: "tabs", tabs: ["revenue", "alerts"], activeTabIndex: 0 },
      ],
    },
  ],
};

// inside <Mosaic>:
renderTabTitle={({ tabKey }) => TITLES[tabKey]}
onChange={(_, meta) => console.log("change:", meta?.type)}

// on each <MosaicWindow>:
toolbarControls={[
  <ExpandButton key="expand" />,
  <RemoveButton key="remove" />,
]}

I clicked the Alerts tab, then Close on Drivers. The meta.type values:

change: tab-select
change: remove
React Mosaic with a Revenue and Alerts tab group, Alerts selected, and Expand and Close buttons on each window
Alerts is the active tab, and closing Drivers let the tab group fill the column.

Mosaic only renders the active tab, the same idea as conditional rendering in React.

Fix the React Mosaic v6 Layout Error (TS2353) in TypeScript

Most older tutorials, including the first version of this page, use the v6 tree with first, second and splitPercentage. The props still accept that shape and convert it, but the v7 MosaicNode type doesn’t:

const layout: MosaicNode<PanelId> = {
  direction: "row",
  first: "orders",
  second: {
    direction: "column",
    first: "drivers",
    second: "revenue",
  },
  splitPercentage: 40,
};
error TS2353: Object literal may only specify known properties, and 'first' does not exist in type 'MosaicSplitNode<PanelId> | MosaicTabsNode<PanelId>'.