examples/solid/contacts-solid-router
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack Solid Query Contacts Example (Solid Router)#
A contacts app whose router loaders read from the query cache and whose mutations invalidate it.
Built with Solid Router.
How it works#
src/services/contacts/queries.tsdefinescontactsQueries.list(q)andcontactsQueries.detail(id)withqueryOptions, keyed by['contacts', 'list', { q }]and['contacts', 'detail', id]. The detailqueryFnthrows "Not Found" when the contact does not exist.src/services/contacts/api.tsstores the contacts inlocalStoragebehind a random fake network delay.src/queryClient.tscreates the sharedQueryClientwith a 10-secondstaleTime.src/index.tsxregisters each route'spreloadfunction.src/routes/root.tsxandsrc/routes/contact.tsxstart the fetch there withqueryClient.query(...), and the components read the same options withuseQuery.src/routes/root.tsxdebounces the search input into theqsearch param withcreateDebouncerfrom TanStack Pacer and shows a spinner whileuseIsFetchingcounts a fetching list query.- The Solid Router actions in
src/routes/new.tsx,src/routes/edit.tsx,src/routes/destroy.tsxandsrc/routes/contact.tsxupdatelocalStorageand then callqueryClient.invalidateQueriesbefore redirecting.
To run this example:
npm installnpm run dev