document: add guide for using props as a key of query
As of https://github.com/TanStack/query/pull/7608. You no longer need an intermediate computed statement for props. You can just use the getter syntax () => props.foo directly. It would probably be worth documenting this as using a computed ref for a simple property access is less efficient than using a getter.
As of #7608. You no longer need an intermediate
computedstatement for props. You can just use the getter syntax() => props.foodirectly. It would probably be worth documenting this as using a computed ref for a simple property access is less efficient than using a getter.
you mean I should do like this?
<script setup>
const props = defineProps([todoId])
const queryKey = ['todos', ()=>props.todoId]
const result = useQuery(queryKey, () => fetchTodoById(todoIdValue.value))
</script>
but it didn't work for me. are these changes merged with the main branch?
As of #7608. You no longer need an intermediate
computedstatement for props. You can just use the getter syntax() => props.foodirectly. It would probably be worth documenting this as using a computed ref for a simple property access is less efficient than using a getter.you mean I should do like this?
<script setup> const props = defineProps([todoId]) const queryKey = ['todos', ()=>props.todoId] const result = useQuery(queryKey, () => fetchTodoById(todoIdValue.value)) </script>but it didn't work for me. are these changes merged with the main branch?
Yes make sure you’re on the latest version of the package.
ok then, I changed the doc to contain these changes.
☁️ Nx Cloud Report
CI is running/has finished running commands for commit 69be23d9977f19daef92a5da48314852a35fe16a. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.
📂 See all runs for this CI Pipeline Execution
✅ Successfully ran 2 targets
Sent with 💌 from NxCloud.
More templates
- @tanstack/query-example-angular-basic
- @tanstack/query-example-angular-infinite-query-with-max-pages
- @tanstack/query-example-angular-pagination
- @tanstack/query-example-angular-router
- @tanstack/query-example-angular-rxjs
- @tanstack/query-example-angular-simple
- @tanstack/query-example-solid-astro
- @tanstack/query-example-solid-basic
- @tanstack/query-example-solid-basic-graphql-request
- @tanstack/query-example-solid-default-query-function
- @tanstack/query-example-solid-simple
- @tanstack/query-example-solid-start-streaming
- @tanstack/query-example-svelte-auto-refetching
- @tanstack/query-example-svelte-basic
- @tanstack/query-example-svelte-load-more-infinite-scroll
- @tanstack/query-example-svelte-optimistic-updates
- @tanstack/query-example-svelte-playground
- @tanstack/query-example-svelte-simple
- @tanstack/query-example-svelte-ssr
- @tanstack/query-example-svelte-star-wars
- @tanstack/query-example-react-algolia
- @tanstack/query-example-react-auto-refetching
- @tanstack/query-example-react-basic
- @tanstack/query-example-react-basic-graphql-request
- @tanstack/query-example-react-default-query-function
- @tanstack/query-example-react-devtools-panel
- @tanstack/query-example-react-infinite-query-with-max-pages
- @tanstack/query-example-react-load-more-infinite-scroll
- @tanstack/query-example-react-nextjs
- @tanstack/query-example-react-nextjs-app-prefetching
- @tanstack/query-example-nextjs-suspense-streaming
- @tanstack/query-example-react-offline
- @tanstack/query-example-react-optimistic-updates-cache
- @tanstack/query-example-react-optimistic-updates-ui
- @tanstack/query-example-react-pagination
- @tanstack/query-example-react-playground
- @tanstack/query-example-react-prefetching
- @tanstack/query-example-react-react-native
- @tanstack/query-example-react-router
- @tanstack/query-example-react-rick-morty
- @tanstack/query-example-react-shadow-dom
- @tanstack/query-example-react-simple
- @tanstack/query-example-react-star-wars
- @tanstack/query-example-react-suspense
- @tanstack/query-example-vue-2.6-basic
- @tanstack/query-example-vue-2.7-basic
- @tanstack/query-example-vue-basic
- @tanstack/query-example-vue-dependent-queries
- @tanstack/query-example-vue-nuxt3
- @tanstack/query-example-vue-persister
- @tanstack/query-example-vue-simple
@tanstack/angular-query-devtools-experimental
pnpm add https://pkg.pr.new/@tanstack/angular-query-devtools-experimental@8088
@tanstack/angular-query-experimental
pnpm add https://pkg.pr.new/@tanstack/angular-query-experimental@8088
@tanstack/eslint-plugin-query
pnpm add https://pkg.pr.new/@tanstack/eslint-plugin-query@8088
@tanstack/query-broadcast-client-experimental
pnpm add https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@8088
@tanstack/query-async-storage-persister
pnpm add https://pkg.pr.new/@tanstack/query-async-storage-persister@8088
@tanstack/query-core
pnpm add https://pkg.pr.new/@tanstack/query-core@8088
@tanstack/query-devtools
pnpm add https://pkg.pr.new/@tanstack/query-devtools@8088
@tanstack/query-persist-client-core
pnpm add https://pkg.pr.new/@tanstack/query-persist-client-core@8088
@tanstack/query-sync-storage-persister
pnpm add https://pkg.pr.new/@tanstack/query-sync-storage-persister@8088
@tanstack/react-query-devtools
pnpm add https://pkg.pr.new/@tanstack/react-query-devtools@8088
@tanstack/react-query
pnpm add https://pkg.pr.new/@tanstack/react-query@8088
@tanstack/react-query-next-experimental
pnpm add https://pkg.pr.new/@tanstack/react-query-next-experimental@8088
@tanstack/react-query-persist-client
pnpm add https://pkg.pr.new/@tanstack/react-query-persist-client@8088
@tanstack/solid-query
pnpm add https://pkg.pr.new/@tanstack/solid-query@8088
@tanstack/solid-query-devtools
pnpm add https://pkg.pr.new/@tanstack/solid-query-devtools@8088
@tanstack/solid-query-persist-client
pnpm add https://pkg.pr.new/@tanstack/solid-query-persist-client@8088
@tanstack/svelte-query-devtools
pnpm add https://pkg.pr.new/@tanstack/svelte-query-devtools@8088
@tanstack/svelte-query
pnpm add https://pkg.pr.new/@tanstack/svelte-query@8088
@tanstack/svelte-query-persist-client
pnpm add https://pkg.pr.new/@tanstack/svelte-query-persist-client@8088
@tanstack/vue-query
pnpm add https://pkg.pr.new/@tanstack/vue-query@8088
@tanstack/vue-query-devtools
pnpm add https://pkg.pr.new/@tanstack/vue-query-devtools@8088
commit: 9b9c095
@TkDodo i've fixed the problem with prettier.
I’ve fixed the problem with prettier.
you’ve worked around prettier. Now prettier runs again and it automatically re-formats again.
see: https://github.com/TanStack/query/pull/8088/commits/9b9c095147eeae6dc2d4f7da1bfcc3b17bc32cf4
I've done it in another way, recheck it @TkDodo .
please use prettier locally; it re-formatted again; gonna close this as it kinda wastes my time, sorry.