If you ever want to disable a query from automatically running, you can use the enabled = false
option.
When enabled
is false
:
status === 'success'
or isSuccess
state.status === 'idle'
or isIdle
state.invalidateQueries
and refetchQueries
calls that would normally result in the query refetching.refetch
can be used to manually trigger the query to fetch.<script>const queryResult = useQuery('todos', fetchTodoList, {enabled: false,})</script>{#if $queryResult.isIdle}<span>Not ready....</span>{#if $queryResult.isLoading}<span>Loading...</span>{:else if $queryResult.isError}<span>Error: {$queryResult.error.message}</span>{:else}{#if $queryResult.isFetching}<div>Refreshing...</div>{/if}{#each $queryResult.data as todo}<Todo {todo} />{/each}{/if}
The latest TanStack news, articles, and resources, sent to your inbox.