Google Antigravity Directory

The #1 directory for Google Antigravity prompts, rules, workflows & MCP servers. Optimized for Gemini 3 agentic development.

Resources

PromptsMCP ServersAntigravity RulesGEMINI.md GuideBest Practices

Company

Submit PromptAntigravityAI.directory

Popular Prompts

Next.js 14 App RouterReact TypeScriptTypeScript AdvancedFastAPI GuideDocker Best Practices

Legal

Privacy PolicyTerms of ServiceContact Us
Featured on FazierFeatured on WayfindioAntigravity AI - Featured on Startup FameFeatured on Wired BusinessFeatured on Twelve ToolsListed on Turbo0Featured on findly.toolsFeatured on Aura++That App ShowAI ToolzShinyLaunchMillion Dot HomepageSolver ToolsFeatured on FazierFeatured on WayfindioAntigravity AI - Featured on Startup FameFeatured on Wired BusinessFeatured on Twelve ToolsListed on Turbo0Featured on findly.toolsFeatured on Aura++That App ShowAI ToolzShinyLaunchMillion Dot HomepageSolver Tools

© 2026 Antigravity AI Directory. All rights reserved.

The #1 directory for Google Antigravity IDE

This website is not affiliated with, endorsed by, or associated with Google LLC. "Google" and "Gemini" are trademarks of Google LLC.

\n\n\n\n
    \n {#each todos as todo (todo.id)}\n
  • \n toggleTodo(todo.id)}\n />\n {todo.text}\n
  • \n {/each}\n
\n```\n\n## Derived Values with $derived\n\nCompute values reactively from state:\n\n```svelte\n\n\n
\n

Items: {itemCount}

\n

Subtotal: ${subtotal.toFixed(2)}

\n

Tax: ${tax.toFixed(2)}

\n

Total: ${total.toFixed(2)}

\n
\n```\n\n## Side Effects with $effect\n\nHandle reactive side effects:\n\n```svelte\n\n```\n\n## Props with $props\n\nDefine component props with type safety:\n\n```svelte\n\n\n
\n

{title}

\n {#if description}\n

{description}

\n {/if}\n
\n```\n\n## Bindable Props with $bindable\n\nCreate two-way bindable props:\n\n```svelte\n\n\n\n```\n\n## Class Components Pattern\n\nEncapsulate logic in class-based state:\n\n```svelte\n\n\n\n{counter.count}\n\n\n```\n\n## Best Practices\n\nFollow these guidelines for Svelte 5 runes:\n\n1. **Use $state for mutable data** - Simple and reactive\n2. **Use $derived for computed values** - Automatic dependency tracking\n3. **Clean up effects** - Return cleanup functions from $effect\n4. **Type your props** - Use interfaces with $props\n5. **Prefer fine-grained reactivity** - Use $state.raw for large objects\n6. **Migrate gradually** - Stores still work alongside runes\n\nGoogle Antigravity IDE provides intelligent rune suggestions and automatic Svelte 4 to 5 migration assistance.","author":{"@type":"Person","name":"Antigravity AI"},"dateCreated":"2026-01-04T02:13:31.983586+00:00","keywords":"Svelte, Reactivity, Frontend, State Management","programmingLanguage":"Antigravity AI Prompt","codeRepository":"https://antigravityai.directory"}
Antigravity AI Directory
PromptsMCPBest PracticesUse CasesLearn
Home
Prompts
Svelte 5 Runes Complete Guide

Svelte 5 Runes Complete Guide

Modern reactivity with Svelte 5 runes for Google Antigravity IDE

SvelteReactivityFrontendState Management
by Antigravity AI
⭐0Stars
.antigravity
# Svelte 5 Runes Complete Guide for Google Antigravity

Master the new Svelte 5 reactivity system with runes in Google Antigravity IDE. This comprehensive guide covers state management with $state, derived values with $derived, side effects with $effect, and the migration path from Svelte 4 stores to the new universal reactivity primitives.

## Configuration

Configure your Antigravity environment for Svelte 5:

```typescript
// .antigravity/svelte.ts
export const svelteConfig = {
  version: "5.x",
  features: {
    runes: true,
    snippets: true,
    eventAttributes: true
  },
  migration: {
    autoConvert: true,
    preserveStores: false
  }
};
```

## Basic State with $state

Create reactive state using the $state rune:

```svelte
<script lang="ts">
  let count = $state(0);
  let user = $state<User | null>(null);
  
  let todos = $state<Todo[]>([
    { id: 1, text: "Learn Svelte 5", done: false },
    { id: 2, text: "Build something", done: false }
  ]);
  
  function addTodo(text: string) {
    todos.push({
      id: Date.now(),
      text,
      done: false
    });
  }
  
  function toggleTodo(id: number) {
    const todo = todos.find(t => t.id === id);
    if (todo) {
      todo.done = !todo.done;
    }
  }
</script>

<button onclick={() => count++}>
  Clicks: {count}
</button>

<ul>
  {#each todos as todo (todo.id)}
    <li class:done={todo.done}>
      <input
        type="checkbox"
        checked={todo.done}
        onchange={() => toggleTodo(todo.id)}
      />
      {todo.text}
    </li>
  {/each}
</ul>
```

## Derived Values with $derived

Compute values reactively from state:

```svelte
<script lang="ts">
  let items = $state<CartItem[]>([]);
  let taxRate = $state(0.08);
  
  let subtotal = $derived(
    items.reduce((sum, item) => sum + item.price * item.quantity, 0)
  );
  
  let tax = $derived(subtotal * taxRate);
  let total = $derived(subtotal + tax);
  
  let itemCount = $derived(
    items.reduce((sum, item) => sum + item.quantity, 0)
  );
  
  let isEmpty = $derived(items.length === 0);
  
  let sortedItems = $derived(
    [...items].sort((a, b) => b.price - a.price)
  );
</script>

<div class="cart-summary">
  <p>Items: {itemCount}</p>
  <p>Subtotal: ${subtotal.toFixed(2)}</p>
  <p>Tax: ${tax.toFixed(2)}</p>
  <p>Total: ${total.toFixed(2)}</p>
</div>
```

## Side Effects with $effect

Handle reactive side effects:

```svelte
<script lang="ts">
  let searchQuery = $state("");
  let results = $state<SearchResult[]>([]);
  let loading = $state(false);
  
  $effect(() => {
    if (searchQuery.length < 3) {
      results = [];
      return;
    }
    
    loading = true;
    const controller = new AbortController();
    
    fetch(`/api/search?q=${encodeURIComponent(searchQuery)}`, {
      signal: controller.signal
    })
      .then(r => r.json())
      .then(data => {
        results = data;
        loading = false;
      })
      .catch(err => {
        if (err.name !== "AbortError") {
          console.error(err);
          loading = false;
        }
      });
    
    return () => controller.abort();
  });
  
  $effect(() => {
    document.title = `Search: ${searchQuery || "Home"}`;
  });
</script>
```

## Props with $props

Define component props with type safety:

```svelte
<script lang="ts">
  interface Props {
    title: string;
    description?: string;
    variant?: "primary" | "secondary";
    onclick?: (event: MouseEvent) => void;
  }
  
  let { 
    title, 
    description = "",
    variant = "primary",
    onclick
  }: Props = $props();
</script>

<div class="card card-{variant}" {onclick}>
  <h2>{title}</h2>
  {#if description}
    <p>{description}</p>
  {/if}
</div>
```

## Bindable Props with $bindable

Create two-way bindable props:

```svelte
<script lang="ts">
  interface Props {
    value: string;
    placeholder?: string;
  }
  
  let { value = $bindable(), placeholder = "" }: Props = $props();
</script>

<input 
  type="text"
  bind:value
  {placeholder}
  class="input"
/>
```

## Class Components Pattern

Encapsulate logic in class-based state:

```svelte
<script lang="ts">
  class Counter {
    count = $state(0);
    
    increment() {
      this.count++;
    }
    
    decrement() {
      this.count--;
    }
    
    reset() {
      this.count = 0;
    }
  }
  
  const counter = new Counter();
</script>

<button onclick={() => counter.decrement()}>-</button>
<span>{counter.count}</span>
<button onclick={() => counter.increment()}>+</button>
<button onclick={() => counter.reset()}>Reset</button>
```

## Best Practices

Follow these guidelines for Svelte 5 runes:

1. **Use $state for mutable data** - Simple and reactive
2. **Use $derived for computed values** - Automatic dependency tracking
3. **Clean up effects** - Return cleanup functions from $effect
4. **Type your props** - Use interfaces with $props
5. **Prefer fine-grained reactivity** - Use $state.raw for large objects
6. **Migrate gradually** - Stores still work alongside runes

Google Antigravity IDE provides intelligent rune suggestions and automatic Svelte 4 to 5 migration assistance.

When to Use This Prompt

This Svelte prompt is ideal for developers working on:

  • Svelte applications requiring modern best practices and optimal performance
  • Projects that need production-ready Svelte code with proper error handling
  • Teams looking to standardize their svelte development workflow
  • Developers wanting to learn industry-standard Svelte patterns and techniques

By using this prompt, you can save hours of manual coding and ensure best practices are followed from the start. It's particularly valuable for teams looking to maintain consistency across their svelte implementations.

How to Use

  1. Copy the prompt - Click the copy button above to copy the entire prompt to your clipboard
  2. Paste into your AI assistant - Use with Claude, ChatGPT, Cursor, or any AI coding tool
  3. Customize as needed - Adjust the prompt based on your specific requirements
  4. Review the output - Always review generated code for security and correctness
💡 Pro Tip: For best results, provide context about your project structure and any specific constraints or preferences you have.

Best Practices

  • ✓ Always review generated code for security vulnerabilities before deploying
  • ✓ Test the Svelte code in a development environment first
  • ✓ Customize the prompt output to match your project's coding standards
  • ✓ Keep your AI assistant's context window in mind for complex requirements
  • ✓ Version control your prompts alongside your code for reproducibility

Frequently Asked Questions

Can I use this Svelte prompt commercially?

Yes! All prompts on Antigravity AI Directory are free to use for both personal and commercial projects. No attribution required, though it's always appreciated.

Which AI assistants work best with this prompt?

This prompt works excellently with Claude, ChatGPT, Cursor, GitHub Copilot, and other modern AI coding assistants. For best results, use models with large context windows.

How do I customize this prompt for my specific needs?

You can modify the prompt by adding specific requirements, constraints, or preferences. For Svelte projects, consider mentioning your framework version, coding style, and any specific libraries you're using.

Related Prompts

💬 Comments

Loading comments...