Agent skill
solid-router-queries
Solid Router queries: query() for data fetching with caching/deduplication, createAsync() for reactive signals, createAsyncStore() for fine-grained reactivity, query keys for revalidation.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/data/solid-router-queries
Metadata
Additional technical details for this skill
- globs
-
[ "**/*router*", "**/routes/**/*" ]
SKILL.md
Solid Router Queries
Defining Queries
Queries provide caching, deduplication, and revalidation:
import { query } from "@solidjs/router";
const getUserQuery = query(async (userId: string) => {
const response = await fetch(`/api/users/${userId}`);
if (!response.ok) {
throw new Error("Failed to fetch user");
}
return response.json();
}, "user");
Query features:
- Automatic request deduplication
- Caching for preloading and navigation
- Server-side deduplication in SSR
- Automatic revalidation after actions
- Browser history navigation reuse
Using Queries with createAsync
import { Show, Suspense, ErrorBoundary } from "solid-js";
import { createAsync, query } from "@solidjs/router";
const getUserQuery = query(async (id: string) => {
// Fetch user
}, "user");
function UserProfile(props: { userId: string }) {
const user = createAsync(() => getUserQuery(props.userId));
return (
<ErrorBoundary fallback={<div>Error loading user</div>}>
<Suspense fallback={<div>Loading...</div>}>
<Show when={user()}>
<div>{user()!.name}</div>
</Show>
</Suspense>
</ErrorBoundary>
);
}
createAsync Options
const data = createAsync(() => getDataQuery(), {
name: "myData", // Debug name
initialValue: [], // Initial value before fetch
deferStream: true // Wait for data before streaming (SSR)
});
deferStream: Set to true when data is critical for SEO or initial render.
createAsyncStore
For large datasets that need fine-grained reactivity:
import { createAsyncStore } from "@solidjs/router";
const getNotificationsQuery = query(async (unreadOnly: boolean) => {
// Fetch notifications
}, "notifications");
function Notifications() {
const notifications = createAsyncStore(() =>
getNotificationsQuery(false),
{ initialValue: [] }
);
// Access as store (direct property access)
return (
<For each={notifications()}>
{(notification) => (
<div>{notification.message}</div>
)}
</For>
);
}
Use createAsyncStore when:
- Working with large, complex data structures
- Need fine-grained reactivity on nested properties
- Want reconciliation when data updates
cache (Deprecated)
Note: cache is deprecated since v0.15.0. Use query instead.
// ❌ Deprecated
import { cache } from "@solidjs/router";
const getUser = cache(async (id) => fetchUser(id), "user");
// ✅ Use query instead
import { query } from "@solidjs/router";
const getUser = query(async (id) => fetchUser(id), "user");
Query Keys
Query keys are generated from name and arguments. Access for revalidation:
const getProductQuery = query(async (id: string) => {
// ...
}, "product");
// Base key - revalidates all instances
getProductQuery.key
// Specific key - revalidates one instance
getProductQuery.keyFor("123")
Best Practices
- Wrap async data with
<Suspense>and<ErrorBoundary> - Use
deferStream: truefor SEO-critical data - Use query names for debugging and devtools
- Use
createAsyncStorefor complex nested data - Access query keys for manual revalidation when needed
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?