Skip to content
Language22
Menu

Docs / Frameworks

Astro

Add UI Loft items to an Astro site. Astro needs React and Tailwind added first, and an item that moves needs a client directive.

Version
React
Needs
React + Tailwind 4 + shadcn
Setup time
About 5 minutes

Set up

  1. Create the site

    Skip this if you already have one.

    Terminal
    npm create astro@latest my-site -- --template minimal --install --no-git --yes
    cd my-site
  2. Add React and Tailwind

    Astro's own command installs both and updates astro.config.mjs. It also makes src/styles/global.css.

    Terminal
    npx astro add react tailwind --yes
  3. Add the @ alias

    Add paths under compilerOptions in tsconfig.json.

    tsconfig.json
    {
      "compilerOptions": {
        "paths": {
          "@/*": ["./src/*"]
        }
      }
    }
  4. Set up shadcn

    It makes a components.json and fills src/styles/global.css with the theme. -d takes the defaults.

    Terminal
    npx shadcn@latest init -d
  5. Add an item

    Copy the command from any item page. The file lands in src/components/.

    Terminal
    npx shadcn@latest add https://uiloft.dev/r/glow-button.json
  6. Use it

    Import the styles once and the item, then give the item client:load so it runs in the browser.

    src/pages/index.astro
    ---
    import "@/styles/global.css"
    import { GlowButton } from "@/components/glow-button"
    ---
    
    <html lang="en">
      <body>
        <GlowButton client:load>Get started</GlowButton>
      </body>
    </html>

Good to know

  • Without a client directive, Astro sends the item as plain HTML: it shows, but doesn't move or react.
  • client:visible instead of client:load waits until the item scrolls into view.
  • With a layout, import @/styles/global.css there once instead of in each page.

Other frameworks