pickstack

SolidJS + TanStack Query

Server state: caching, refetching, loading and error states. This page shows exactly what pickstack adds to a SolidJS project for TanStack Query: the packages, the new files and the changes to existing ones. Every combination is installed, built, linted and tested in CI.

$ npm create pickstack@latest my-app -- --framework solid --modules tanstack-query --yes
Customize in the configurator

Packages it adds

PackageVersionType
@tanstack/solid-query^5.108.4runtime

New files

public/stack.json
["SolidJS", "Vite", "TypeScript", "TanStack Query"]
src/api/stack.ts
/** Loads the stack list served from `public/stack.json`. */
export async function fetchStack(): Promise<string[]> {
  const response = await fetch(`${import.meta.env.BASE_URL}stack.json`);
  if (!response.ok) throw new Error(`Request failed: ${response.status}`);
  return response.json();
}
src/components/StackList.tsx
import { useQuery } from "@tanstack/solid-query";
import { Match, Switch } from "solid-js";
import { fetchStack } from "../api/stack";

export default function StackList() {
  const stack = useQuery(() => ({ queryKey: ["stack"], queryFn: fetchStack }));

  return (
    <p class="text">
      <Switch>
        <Match when={stack.isPending}>Loading…</Match>
        <Match when={stack.isError}>Could not load the stack.</Match>
        <Match when={stack.data}>
          {(data) => `Built with ${data().join(", ")}.`}
        </Match>
      </Switch>
    </p>
  );
}

Changes to existing files

src/App.tsx (changed)
 import Counter from "./components/Counter";+import StackList from "./components/StackList";   export default function App() {   return (     <main class="app">       <h1 class="title">my-app</h1>       <Counter />+      <StackList />     </main>   ); }⋯ 1 unchanged lines
src/index.tsx (changed)
 /* @refresh reload */+import { QueryClient, QueryClientProvider } from "@tanstack/solid-query"; import { render } from "solid-js/web"; import App from "./App"; import "./index.css";  +const queryClient = new QueryClient();+  const root = document.getElementById("root");  +render(+  () => (+    <QueryClientProvider client={queryClient}>+      <App />+    </QueryClientProvider>+  ),+  root!,+);−render(() => <App />, root!);  

Project files

Related templates