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.

Antigravity AI Directory
PromptsMCPBest PracticesUse CasesLearn
Home
Prompts
Nanostores Atomic State

Nanostores Atomic State

Minimal atomic state with Nanostores for Google Antigravity projects including stores, computed values, and framework integration.

nanostoresstate-managementatomicreacttypescript
by Antigravity Team
⭐0Stars
.antigravity
# Nanostores Atomic State for Google Antigravity

Implement minimal atomic state management with Nanostores in your Google Antigravity IDE projects. This comprehensive guide covers store creation, computed values, and framework integration optimized for Gemini 3 agentic development.

## Store Creation

Create atomic stores with Nanostores:

```typescript
// stores/prompts.ts
import { atom, map, computed } from 'nanostores';

// Primitive atom
export const $searchQuery = atom('');
export const $selectedTag = atom<string | null>(null);
export const $isLoading = atom(false);

// Map store for complex objects
interface Prompt {
  id: string;
  title: string;
  description: string;
  tags: string[];
  starred: boolean;
}

export const $prompts = map<Record<string, Prompt>>({});

// Computed values
export const $promptList = computed($prompts, (prompts) =>
  Object.values(prompts)
);

export const $filteredPrompts = computed(
  [$promptList, $searchQuery, $selectedTag],
  (prompts, search, tag) => {
    return prompts.filter((prompt) => {
      const matchesSearch = !search ||
        prompt.title.toLowerCase().includes(search.toLowerCase()) ||
        prompt.description.toLowerCase().includes(search.toLowerCase());
      
      const matchesTag = !tag || prompt.tags.includes(tag);
      
      return matchesSearch && matchesTag;
    });
  }
);

export const $starredPrompts = computed($promptList, (prompts) =>
  prompts.filter((p) => p.starred)
);

export const $stats = computed([$promptList, $starredPrompts], (all, starred) => ({
  total: all.length,
  starred: starred.length,
}));
```

## Store Actions

Define actions for store mutations:

```typescript
// stores/actions.ts
import { $prompts, $isLoading, $searchQuery } from './prompts';

export async function fetchPrompts() {
  $isLoading.set(true);
  
  try {
    const response = await fetch('/api/prompts');
    const data = await response.json();
    
    const promptsMap: Record<string, Prompt> = {};
    data.prompts.forEach((prompt: Prompt) => {
      promptsMap[prompt.id] = prompt;
    });
    
    $prompts.set(promptsMap);
  } catch (error) {
    console.error('Failed to fetch prompts:', error);
  } finally {
    $isLoading.set(false);
  }
}

export function addPrompt(prompt: Prompt) {
  $prompts.setKey(prompt.id, prompt);
}

export function updatePrompt(id: string, updates: Partial<Prompt>) {
  const current = $prompts.get()[id];
  if (current) {
    $prompts.setKey(id, { ...current, ...updates });
  }
}

export function toggleStar(id: string) {
  const current = $prompts.get()[id];
  if (current) {
    $prompts.setKey(id, { ...current, starred: !current.starred });
  }
}

export function removePrompt(id: string) {
  const prompts = { ...$prompts.get() };
  delete prompts[id];
  $prompts.set(prompts);
}

export function setSearch(query: string) {
  $searchQuery.set(query);
}
```

## React Integration

Use Nanostores in React components:

```typescript
// components/PromptList.tsx
'use client';

import { useStore } from '@nanostores/react';
import { useEffect } from 'react';
import {
  $filteredPrompts,
  $isLoading,
  $stats,
  $searchQuery,
} from '@/stores/prompts';
import { fetchPrompts, toggleStar, setSearch } from '@/stores/actions';

export function PromptList() {
  const prompts = useStore($filteredPrompts);
  const isLoading = useStore($isLoading);
  const stats = useStore($stats);
  const search = useStore($searchQuery);

  useEffect(() => {
    fetchPrompts();
  }, []);

  if (isLoading) {
    return <LoadingSkeleton />;
  }

  return (
    <div>
      <div className="stats">
        <span>Total: {stats.total}</span>
        <span>Starred: {stats.starred}</span>
      </div>

      <input
        type="search"
        value={search}
        onChange={(e) => setSearch(e.target.value)}
        placeholder="Search prompts..."
      />

      <div className="grid">
        {prompts.map((prompt) => (
          <PromptCard
            key={prompt.id}
            prompt={prompt}
            onStar={() => toggleStar(prompt.id)}
          />
        ))}
      </div>
    </div>
  );
}
```

## Persistent Storage

Add persistence with localStorage:

```typescript
// stores/persistent.ts
import { persistentAtom, persistentMap } from '@nanostores/persistent';

// Persisted atom
export const $starredIds = persistentAtom<string[]>(
  'starred-prompts',
  [],
  {
    encode: JSON.stringify,
    decode: JSON.parse,
  }
);

// Persisted map
export const $userPreferences = persistentMap<{
  theme: 'light' | 'dark';
  sortBy: 'date' | 'stars' | 'views';
  showStarred: boolean;
}>(
  'user-preferences',
  {
    theme: 'dark',
    sortBy: 'date',
    showStarred: false,
  }
);

// Actions for persistent stores
export function toggleStarredId(id: string) {
  const current = $starredIds.get();
  
  if (current.includes(id)) {
    $starredIds.set(current.filter((i) => i !== id));
  } else {
    $starredIds.set([...current, id]);
  }
}

export function setTheme(theme: 'light' | 'dark') {
  $userPreferences.setKey('theme', theme);
}

export function setSortBy(sortBy: 'date' | 'stars' | 'views') {
  $userPreferences.setKey('sortBy', sortBy);
}
```

## Async Tasks

Handle async operations with tasks:

```typescript
// stores/tasks.ts
import { task } from 'nanostores';

// Async task store
export const $fetchPromptTask = task(async (slug: string) => {
  const response = await fetch(`/api/prompts/${slug}`);
  
  if (!response.ok) {
    throw new Error('Prompt not found');
  }
  
  return response.json();
});

// Usage in component
function PromptDetail({ slug }: { slug: string }) {
  const taskState = useStore($fetchPromptTask);

  useEffect(() => {
    $fetchPromptTask.run(slug);
  }, [slug]);

  if (taskState.loading) {
    return <LoadingSkeleton />;
  }

  if (taskState.error) {
    return <ErrorMessage error={taskState.error} />;
  }

  return <PromptContent prompt={taskState.data} />;
}
```

## Best Practices

1. **Keep stores small** and focused
2. **Use computed** for derived values
3. **Separate actions** from store definitions
4. **Use persistentAtom** for localStorage
5. **Leverage task** for async operations
6. **Use map** for keyed collections
7. **Subscribe carefully** to avoid memory leaks

When to Use This Prompt

This nanostores prompt is ideal for developers working on:

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

Related Prompts

💬 Comments

Loading comments...