BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/dnd-grid/portal-example

Portal

dnd-grid/portal-example
FreeComponent

Render the grid into a portal container.

Install it

npx shadcn@latest add https://dnd-grid.com/r/portal-example.json

Source

examples/dnd-grid-portal-example.tsxdnd-grid.com/r/portal-example.json
1"use client";
2
3import { DndGrid, type Layout } from "@dnd-grid/react";
4import { useEffect, useRef, useState } from "react";
5import { createPortal } from "react-dom";
6
7const initialLayout: Layout = [
8 { id: "p1", x: 0, y: 0, w: 3, h: 2 },
9 { id: "p2", x: 3, y: 0, w: 3, h: 2 },
10 { id: "p3", x: 6, y: 0, w: 3, h: 2 },
11 { id: "p4", x: 9, y: 0, w: 3, h: 2 },
12];
13
14export function PortalExample() {
15 const [layout, setLayout] = useState<Layout>(initialLayout);
16 const portalRef = useRef<HTMLDivElement>(null);
17 const [mounted, setMounted] = useState(false);
18
19 useEffect(() => {
20 setMounted(true);
21 }, []);
22
23 const grid = (
24 <DndGrid
25 cols={12}
26 layout={layout}
27 onLayoutChange={setLayout}
28 rowHeight={50}
29 >
30 {layout.map((item) => (
31 <div className="grid-item" key={item.id}>
32 {item.id}
33 </div>
34 ))}
35 </DndGrid>
36 );
37
38 return (
39 <div className="space-y-4">
40 <div className="text-xs text-zinc-500">
41 Grid rendered via createPortal into a separate container.
42 </div>
43 <div
44 className="min-h-[200px] rounded-lg border border-zinc-300 border-dashed p-4"
45 ref={portalRef}
46 />
47 {mounted && portalRef.current && createPortal(grid, portalRef.current)}
48 </div>
49 );
50}

What it pulls in

npm packages

  • @dnd-grid/react
  • react-draggable
  • react-resizable

Files it writes

  • examples/dnd-grid-portal-example.tsx

Facts

Registry
dnd-grid
Type
registry:component
Access
Free
Files written
1
Licence
MIT
First indexed
2026-08-01
Last confirmed
yesterday

Go to the source

dnd-grid.com mblode/dnd-grid on GitHub Raw registry item This item as JSON

More from dnd-grid

All 19 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
Allow overlapallow-overlap-examplednd-gridComponentsFree3 deps
Aspect ratio constraintsaspect-ratio-constraints-examplednd-gridComponentsFree3 deps
Basic examplebasic-examplednd-gridComponentsFree3 deps
Boundedbounded-examplednd-gridComponentsFree3 deps
Compactor showcasecompactor-showcase-examplednd-gridComponentsFree3 deps
Compositioncomposition-examplednd-gridComponentsFree3 deps
Constraintsconstraints-examplednd-gridComponentsFree3 deps
Drag from outsidedrag-from-outside-examplednd-gridComponentsFree3 deps
BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex