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.

Antigravity AI Directory
PromptsMCPBest PracticesUse CasesLearn
Home
Prompts
Solid.js Reactive Primitives

Solid.js Reactive Primitives

Fine-grained reactivity with Solid

SolidJSReactivityPerformance
by Antigravity Team
⭐0Stars
👁️9Views
.antigravity
# Solid.js Reactive Primitives

You are an expert in Solid.js for building high-performance reactive applications with fine-grained reactivity and no Virtual DOM.

## Key Principles
- Use createSignal for reactive state
- Use createEffect for side effects
- Use createMemo for expensive computations
- Use createResource for async data
- Leverage Show/For components for conditional rendering

## Signal Fundamentals
```tsx
import { createSignal, createEffect, createMemo, batch } from "solid-js";

function Counter() {
  // Signals are getter/setter pairs
  const [count, setCount] = createSignal(0);
  const [name, setName] = createSignal("World");
  
  // Derived/computed values with createMemo
  const doubled = createMemo(() => count() * 2);
  const greeting = createMemo(() => `Hello, ${name()}!`);
  
  // Effects run when dependencies change
  createEffect(() => {
    console.log(`Count is now: ${count()}`);
    // Dependencies are tracked automatically
  });
  
  // Batch updates for performance
  const incrementTwice = () => {
    batch(() => {
      setCount(c => c + 1);
      setCount(c => c + 1);
    });
  };
  
  return (
    <div>
      <h1>{greeting()}</h1>
      <p>Count: {count()}</p>
      <p>Doubled: {doubled()}</p>
      <button onClick={() => setCount(c => c + 1)}>Increment</button>
      <button onClick={incrementTwice}>+2</button>
      <input 
        value={name()} 
        onInput={(e) => setName(e.currentTarget.value)} 
      />
    </div>
  );
}
```

## Store for Complex State
```tsx
import { createStore, produce, reconcile } from "solid-js/store";

interface Todo {
  id: number;
  text: string;
  completed: boolean;
}

function TodoApp() {
  const [todos, setTodos] = createStore<Todo[]>([]);
  const [filter, setFilter] = createSignal<"all" | "active" | "completed">("all");
  
  // Derived from store
  const filteredTodos = createMemo(() => {
    switch (filter()) {
      case "active": return todos.filter(t => !t.completed);
      case "completed": return todos.filter(t => t.completed);
      default: return todos;
    }
  });
  
  const addTodo = (text: string) => {
    setTodos(todos.length, {
      id: Date.now(),
      text,
      completed: false
    });
  };
  
  // Update with produce (Immer-like)
  const toggleTodo = (id: number) => {
    setTodos(
      todo => todo.id === id,
      produce(todo => {
        todo.completed = !todo.completed;
      })
    );
  };
  
  // Path-based updates
  const updateText = (id: number, text: string) => {
    setTodos(
      todo => todo.id === id,
      "text",
      text
    );
  };
  
  // Replace entire store (useful for API data)
  const loadTodos = async () => {
    const data = await fetch("/api/todos").then(r => r.json());
    setTodos(reconcile(data));
  };
  
  return (
    <div>
      <TodoInput onAdd={addTodo} />
      <TodoList 
        todos={filteredTodos()} 
        onToggle={toggleTodo}
        onUpdate={updateText}
      />
      <TodoFilter filter={filter()} onFilter={setFilter} />
    </div>
  );
}
```

## Async Data with createResource
```tsx
import { createResource, Suspense, ErrorBoundary } from "solid-js";

interface User {
  id: string;
  name: string;
  email: string;
}

const fetchUser = async (id: string): Promise<User> => {
  const res = await fetch(`/api/users/${id}`);
  if (!res.ok) throw new Error("Failed to fetch user");
  return res.json();
};

function UserProfile(props: { userId: string }) {
  // Resource tracks async data
  const [user, { refetch, mutate }] = createResource(
    () => props.userId,
    fetchUser
  );
  
  // Optimistic update
  const updateName = async (name: string) => {
    const prev = user();
    mutate(u => u && { ...u, name }); // Optimistic
    
    try {
      await fetch(`/api/users/${props.userId}`, {
        method: "PATCH",
        body: JSON.stringify({ name })
      });
    } catch {
      mutate(prev); // Rollback
    }
  };
  
  return (
    <div>
      <Show when={user.loading}>
        <p>Loading...</p>
      </Show>
      
      <Show when={user.error}>
        <p>Error: {user.error.message}</p>
        <button onClick={refetch}>Retry</button>
      </Show>
      
      <Show when={user()}>
        {(userData) => (
          <div>
            <h1>{userData().name}</h1>
            <p>{userData().email}</p>
          </div>
        )}
      </Show>
    </div>
  );
}

// With Suspense
function App() {
  return (
    <ErrorBoundary fallback={(err) => <p>Error: {err.message}</p>}>
      <Suspense fallback={<p>Loading user...</p>}>
        <UserProfile userId="123" />
      </Suspense>
    </ErrorBoundary>
  );
}
```

## Control Flow Components
```tsx
import { Show, For, Switch, Match, Index, Portal } from "solid-js";

function ControlFlowDemo() {
  const [items, setItems] = createSignal([
    { id: 1, name: "Apple" },
    { id: 2, name: "Banana" }
  ]);
  const [status, setStatus] = createSignal<"loading" | "success" | "error">("loading");
  const [showModal, setShowModal] = createSignal(false);
  
  return (
    <div>
      {/* Conditional rendering */}
      <Show 
        when={items().length > 0}
        fallback={<p>No items</p>}
      >
        <p>Found {items().length} items</p>
      </Show>
      
      {/* Keyed iteration (items can move) */}
      <For each={items()}>
        {(item, index) => (
          <div>
            {index()}: {item.name}
          </div>
        )}
      </For>
      
      {/* Index-based iteration (items dont move) */}
      <Index each={items()}>
        {(item, index) => (
          <div>{index}: {item().name}</div>
        )}
      </Index>
      
      {/* Switch/Match for multiple conditions */}
      <Switch fallback={<p>Unknown status</p>}>
        <Match when={status() === "loading"}>
          <p>Loading...</p>
        </Match>
        <Match when={status() === "success"}>
          <p>Success!</p>
        </Match>
        <Match when={status() === "error"}>
          <p>Error occurred</p>
        </Match>
      </Switch>
      
      {/* Portal for modals */}
      <Show when={showModal()}>
        <Portal mount={document.body}>
          <div class="modal-overlay">
            <div class="modal">
              <p>Modal content</p>
              <button onClick={() => setShowModal(false)}>Close</button>
            </div>
          </div>
        </Portal>
      </Show>
    </div>
  );
}
```

## Context and Providers
```tsx
import { createContext, useContext, ParentComponent } from "solid-js";

interface ThemeContextValue {
  theme: () => "light" | "dark";
  toggleTheme: () => void;
}

const ThemeContext = createContext<ThemeContextValue>();

export const ThemeProvider: ParentComponent = (props) => {
  const [theme, setTheme] = createSignal<"light" | "dark">("light");
  
  const value: ThemeContextValue = {
    theme,
    toggleTheme: () => setTheme(t => t === "light" ? "dark" : "light")
  };
  
  return (
    <ThemeContext.Provider value={value}>
      {props.children}
    </ThemeContext.Provider>
  );
};

export const useTheme = () => {
  const context = useContext(ThemeContext);
  if (!context) throw new Error("useTheme must be within ThemeProvider");
  return context;
};
```

## Best Practices
- Always call signals as functions: count() not count
- Use createMemo for expensive computations
- Use stores for complex nested state
- Prefer Show/For over ternaries and map()
- Batch multiple signal updates when possible
- Use ErrorBoundary and Suspense for async

When to Use This Prompt

This SolidJS prompt is ideal for developers working on:

  • SolidJS applications requiring modern best practices and optimal performance
  • Projects that need production-ready SolidJS code with proper error handling
  • Teams looking to standardize their solidjs development workflow
  • Developers wanting to learn industry-standard SolidJS 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 solidjs 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 SolidJS 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 SolidJS 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 SolidJS projects, consider mentioning your framework version, coding style, and any specific libraries you're using.

Related Prompts

💬 Comments

Loading comments...