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 --yesCustomize in the configurator
Packages it adds
| Package | Version | Type |
|---|---|---|
@tanstack/solid-query | ^5.108.4 | runtime |
New files
["SolidJS", "Vite", "TypeScript", "TanStack Query"]
/** 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();
}
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
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
/* @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
.gitignoreREADME.mdindex.htmlpackage.jsonpublic/stack.jsonsrc/App.tsxsrc/api/stack.tssrc/components/Counter.tsxsrc/components/StackList.tsxsrc/index.csssrc/index.tsxtsconfig.app.jsontsconfig.jsontsconfig.node.jsonvite.config.ts