Loading...
Error: {query.error.message}
{todo.title}
}Projects: ${dashboard.projects.length}
` } } ``` -------------------------------- ### Install Project Dependencies with pnpm Source: https://github.com/tanstack/query/blob/main/CONTRIBUTING.md Installs all required project dependencies using pnpm. Run this command after forking and cloning the repository. ```bash pnpm install ``` -------------------------------- ### Start the Svelte development server Source: https://github.com/tanstack/query/blob/main/examples/svelte/basic/README.md Run `npm run dev` to start the development server. Add `-- --open` to automatically open the application in a new browser tab. ```bash npm run dev ``` ```bash # or start the server and open the app in a new browser tab npm run dev -- --open ``` -------------------------------- ### Install Lit Query with yarn Source: https://github.com/tanstack/query/blob/main/docs/framework/lit/installation.md Use yarn to install the Lit Query adapter, TanStack Query Core, and Lit. ```bash yarn add @tanstack/lit-query @tanstack/query-core lit ``` -------------------------------- ### Example Usage of createQueryController in LitElement Source: https://github.com/tanstack/query/blob/main/docs/framework/lit/reference/functions/createQueryController.md This example demonstrates how to integrate `createQueryController` into a LitElement to fetch and render a list of todos, including handling loading and error states. ```ts import { LitElement, html } from 'lit' import { createQueryController } from '@tanstack/lit-query' class TodosView extends LitElement { private readonly todos = createQueryController(this, { queryKey: ['todos'], queryFn: async () => fetch('/api/todos').then((r) => r.json()), }) render() { const query = this.todos() if (query.isPending) return html`Loading...` if (query.isError) return html`Error` return html`Projects: ${dashboard.projects.length}
` } } ``` ``` -------------------------------- ### Basic Usage: Persist QueryClient to localStorage Source: https://github.com/tanstack/query/blob/main/docs/framework/react/plugins/createSyncStoragePersister.md This example shows how to initialize a `QueryClient`, create a `createSyncStoragePersister` instance using `window.localStorage`, and then pass it to `persistQueryClient` to enable state persistence. ```tsx import { persistQueryClient } from '@tanstack/react-query-persist-client' import { createSyncStoragePersister } from '@tanstack/query-sync-storage-persister' const queryClient = new QueryClient({ defaultOptions: { queries: { gcTime: 1000 * 60 * 60 * 24, // 24 hours }, }, }) const localStoragePersister = createSyncStoragePersister({ storage: window.localStorage, }) // const sessionStoragePersister = createSyncStoragePersister({ storage: window.sessionStorage }) persistQueryClient({ queryClient, persister: localStoragePersister, }) ``` -------------------------------- ### Install TanStack Query ESLint Plugin Source: https://github.com/tanstack/query/blob/main/docs/eslint/eslint-plugin-query.md Install the ESLint plugin as a development dependency using your preferred package manager. ```bash npm i -D @tanstack/eslint-plugin-query ``` ```bash pnpm add -D @tanstack/eslint-plugin-query ``` ```bash yarn add -D @tanstack/eslint-plugin-query ``` ```bash bun add -D @tanstack/eslint-plugin-query ``` -------------------------------- ### Preview Production Build Locally Source: https://github.com/tanstack/query/blob/main/examples/solid/astro/README.md Allows for a local preview of the built production site before deployment, ensuring everything works as expected. ```sh npm run preview ``` -------------------------------- ### Create New Astro Minimal Project Source: https://github.com/tanstack/query/blob/main/examples/solid/astro/README.md Use this command to initialize a new Astro project with the minimal template. ```sh npm create astro@latest -- --template minimal ``` -------------------------------- ### Start Development Server with Angular CLI Source: https://github.com/tanstack/query/blob/main/integrations/angular-cli-20/README.md Use this command to launch a local development server, making the application accessible in a browser and enabling automatic reloads on file changes. ```bash ng serve ``` -------------------------------- ### Creating a new Svelte project Source: https://github.com/tanstack/query/blob/main/examples/svelte/load-more-infinite-scroll/README.md Use these commands to initialize a new Svelte project, either in the current directory or a specified new directory. ```bash # create a new project in the current directory npm create svelte@latest # create a new project in my-app npm create svelte@latest my-app ``` -------------------------------- ### Configure QueryClient with experimental_createQueryPersister Source: https://github.com/tanstack/query/blob/main/docs/framework/vue/plugins/createPersister.md Create an `experimental_createQueryPersister` instance with a storage and `maxAge`, then apply its `persisterFn` to the `defaultOptions.queries` of your `QueryClient`. ```tsx import { QueryClient } from '@tanstack/vue-query' import { experimental_createQueryPersister } from '@tanstack/query-persist-client-core' const persister = experimental_createQueryPersister({ storage: AsyncStorage, maxAge: 1000 * 60 * 60 * 12, // 12 hours }) const queryClient = new QueryClient({ defaultOptions: { queries: { gcTime: 1000 * 30, // 30 seconds persister: persister.persisterFn, }, }, }) ``` -------------------------------- ### Basic Article and Comments Components in Solid.js Source: https://github.com/tanstack/query/blob/main/docs/framework/solid/guides/prefetching.md Illustrates basic data fetching for an article and its comments using `useQuery` in Solid.js components without explicit prefetching. ```tsx import { Switch, Match } from 'solid-js' function Article(props) { const articleQuery = useQuery(() => ({ queryKey: ['article', props.id], queryFn: getArticleById, })) return (${mutation.error.message}
` : null} ${mutation.isSuccess ? html`Todo added
` : null}