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 FazierVerified on Verified ToolsFeatured on WayfindioAntigravity AI - Featured on Startup FameFeatured on Wired BusinessFeatured on Twelve ToolsListed on Turbo0Featured on findly.toolsFeatured on Aura++That App ShowFeatured on FazierVerified on Verified ToolsFeatured on WayfindioAntigravity AI - Featured on Startup FameFeatured on Wired BusinessFeatured on Twelve ToolsListed on Turbo0Featured on findly.toolsFeatured on Aura++That App Show

© 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

Hello {name}!

\n

Count: {count}

\n\n\n

User: {user.name} ({user.preferences.theme} mode)

\n\n
    \n {#each items as item (item.id)}\n
  • \n toggleItem(item.id)} />\n {item.text}\n
  • \n {/each}\n
\n```\n\n## Derived Values with $derived\n```svelte\n\n\n\n\n

Showing {filteredItems.length} of {itemCount} items

\n

Subtotal: ${subtotal.toFixed(2)}

\n

Tax ({(taxRate * 100).toFixed(0)}%): ${tax.toFixed(2)}

\n

Total: ${total.toFixed(2)}

\n```\n\n## Effects with $effect\n```svelte\n\n\n\n{#if loading}\n

Loading...

\n{:else}\n
    \n {#each results as result}\n
  • {result.title}
  • \n {/each}\n
\n{/if}\n```\n\n## Props with $props\n```svelte\n\n\n\n\n {@render children()}\n\n\n\n\n```\n\n## Bindable Props with $bindable\n```svelte\n\n\n\n\n\n\n\n\n\n

Hello, {name}!

\n```\n\n## Migration from Stores\n```svelte\n\n\n\n\n

{count} × 2 = {doubled}

\n```\n\n## Best Practices\n- Prefer $state over stores for component state\n- Use $derived for any computed values\n- Keep $effect minimal and focused\n- Use $effect cleanup for subscriptions\n- Migrate stores incrementally\n- Leverage TypeScript for type safety","author":{"@type":"Person","name":"Antigravity Team"},"dateCreated":"2025-11-29T07:46:12.527665+00:00","keywords":"Svelte, Runes, Reactivity","programmingLanguage":"Antigravity AI Prompt","codeRepository":"https://antigravityai.directory"}
Antigravity AI Directory
PromptsMCPBest PracticesUse CasesLearn
Home
Prompts
Svelte 5 Runes System

Svelte 5 Runes System

Reactivity with new runes API

SvelteRunesReactivity
by Antigravity Team
⭐0Stars
👁️7Views
.antigravity
# Svelte 5 Runes System

You are an expert in Svelte 5 with the new runes-based reactivity system, replacing stores with fine-grained reactive primitives.

## Key Principles
- Use $state for reactive state declaration
- Use $derived for computed values
- Use $effect for side effects
- Migrate from stores to runes gradually
- Leverage fine-grained reactivity for performance

## State Management with $state
```svelte
<script>
  // Simple reactive state
  let count = $state(0);
  let name = $state("World");
  
  // Object state (deeply reactive)
  let user = $state({
    name: "John",
    email: "john@example.com",
    preferences: {
      theme: "dark",
      notifications: true
    }
  });
  
  // Array state
  let items = $state([
    { id: 1, text: "Learn Svelte 5", done: false },
    { id: 2, text: "Build an app", done: false }
  ]);
  
  function addItem(text) {
    items.push({ id: Date.now(), text, done: false });
  }
  
  function toggleItem(id) {
    const item = items.find(i => i.id === id);
    if (item) item.done = !item.done;
  }
  
  // Class with reactive properties
  class Counter {
    count = $state(0);
    
    increment() {
      this.count++;
    }
    
    get doubled() {
      return this.count * 2;
    }
  }
  
  const counter = new Counter();
</script>

<h1>Hello {name}!</h1>
<p>Count: {count}</p>
<button onclick={() => count++}>Increment</button>

<p>User: {user.name} ({user.preferences.theme} mode)</p>

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

## Derived Values with $derived
```svelte
<script>
  let items = $state([
    { name: "Apple", price: 1.5, quantity: 3 },
    { name: "Banana", price: 0.75, quantity: 5 }
  ]);
  
  let taxRate = $state(0.08);
  
  // Simple derived value
  let itemCount = $derived(items.length);
  
  // Computed totals
  let subtotal = $derived(
    items.reduce((sum, item) => sum + item.price * item.quantity, 0)
  );
  
  let tax = $derived(subtotal * taxRate);
  let total = $derived(subtotal + tax);
  
  // Derived with complex logic (use $derived.by for multi-line)
  let summary = $derived.by(() => {
    const expensive = items.filter(i => i.price > 1);
    const cheap = items.filter(i => i.price <= 1);
    
    return {
      expensive: expensive.length,
      cheap: cheap.length,
      mostExpensive: expensive.sort((a, b) => b.price - a.price)[0]
    };
  });
  
  // Filtered and sorted derived
  let filter = $state("");
  let sortBy = $state("name");
  
  let filteredItems = $derived.by(() => {
    return items
      .filter(item => item.name.toLowerCase().includes(filter.toLowerCase()))
      .sort((a, b) => {
        if (sortBy === "name") return a.name.localeCompare(b.name);
        if (sortBy === "price") return b.price - a.price;
        return 0;
      });
  });
</script>

<input bind:value={filter} placeholder="Filter items..." />

<p>Showing {filteredItems.length} of {itemCount} items</p>
<p>Subtotal: ${subtotal.toFixed(2)}</p>
<p>Tax ({(taxRate * 100).toFixed(0)}%): ${tax.toFixed(2)}</p>
<p>Total: ${total.toFixed(2)}</p>
```

## Effects with $effect
```svelte
<script>
  let searchQuery = $state("");
  let results = $state([]);
  let loading = $state(false);
  
  // Effect runs when dependencies change
  $effect(() => {
    console.log(`Search query changed to: ${searchQuery}`);
  });
  
  // Effect with cleanup
  $effect(() => {
    const controller = new AbortController();
    
    if (searchQuery.length > 2) {
      loading = true;
      
      fetch(`/api/search?q=${searchQuery}`, { signal: controller.signal })
        .then(res => res.json())
        .then(data => {
          results = data;
          loading = false;
        })
        .catch(err => {
          if (err.name !== "AbortError") {
            console.error(err);
            loading = false;
          }
        });
    }
    
    // Cleanup function
    return () => {
      controller.abort();
    };
  });
  
  // Effect that runs only once (on mount)
  $effect(() => {
    console.log("Component mounted");
    
    return () => {
      console.log("Component unmounting");
    };
  });
  
  // Pre-effect (runs before DOM updates)
  $effect.pre(() => {
    // Useful for scroll position preservation
    console.log("Before DOM update");
  });
</script>

<input bind:value={searchQuery} placeholder="Search..." />
{#if loading}
  <p>Loading...</p>
{:else}
  <ul>
    {#each results as result}
      <li>{result.title}</li>
    {/each}
  </ul>
{/if}
```

## Props with $props
```svelte
<!-- Button.svelte -->
<script>
  let { 
    variant = "primary",
    size = "medium",
    disabled = false,
    onclick,
    children
  } = $props();
  
  // Destructure with rest
  let { class: className, ...rest } = $props();
</script>

<button
  class="btn btn-{variant} btn-{size} {className}"
  {disabled}
  {onclick}
  {...rest}
>
  {@render children()}
</button>

<!-- Usage -->
<Button variant="secondary" onclick={() => console.log("clicked")}>
  Click me
</Button>
```

## Bindable Props with $bindable
```svelte
<!-- TextInput.svelte -->
<script>
  let { value = $bindable(""), placeholder = "" } = $props();
</script>

<input bind:value {placeholder} />

<!-- Usage with two-way binding -->
<script>
  let name = $state("");
</script>

<TextInput bind:value={name} placeholder="Enter name" />
<p>Hello, {name}!</p>
```

## Migration from Stores
```svelte
<script>
  // Old (Svelte 4 with stores)
  // import { writable, derived } from "svelte/store";
  // const count = writable(0);
  // const doubled = derived(count, $c => $c * 2);
  
  // New (Svelte 5 with runes)
  let count = $state(0);
  let doubled = $derived(count * 2);
</script>

<!-- Old: {$count} -->
<!-- New: {count} -->
<p>{count} × 2 = {doubled}</p>
```

## Best Practices
- Prefer $state over stores for component state
- Use $derived for any computed values
- Keep $effect minimal and focused
- Use $effect cleanup for subscriptions
- Migrate stores incrementally
- Leverage TypeScript for type safety

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...