sunny-green
sunny-green4w ago

how to disable query at pageload resource

how to disable query for a page
2 Replies
kapa.ai
kapa.ai4w ago
Hi @japope. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To disable a query at page load for a resource in refine, you can use the queryOptions property with the enabled option set to false. This ensures that the query does not run automatically when the page loads. Here is an example of how you can achieve this using the useShow hook:
const { queryResult } = useShow({
resource: 'your-resource-name',
id: yourResourceId,
queryOptions: {
enabled: false, // This disables the query on page load
},
});

const { data, isLoading } = queryResult;
console.log('Data:', data);
const { queryResult } = useShow({
resource: 'your-resource-name',
id: yourResourceId,
queryOptions: {
enabled: false, // This disables the query on page load
},
});

const { data, isLoading } = queryResult;
console.log('Data:', data);
This approach can be applied to other data-related hooks like useMany, useOne, etc., by setting the enabled option within queryOptions. For more information, you can refer to the following knowledge sources: - How to ensure a query is only run after a certain variable is available and not on load (https://refine.dev/docs/guides-concepts/faq/#how-can-i-ensure-a-query-is-only-run-after-a-certain-variable-is-available-and-not-on-load) - Adding queryOptions to useShow hook (https://github.com/refinedev/refine/issues/3023) If you need to handle custom invalidation or other advanced scenarios, you can refer to the Custom Invalidation guide (https://refine.dev/docs/guides-concepts/forms/#custom-invalidation). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai4w ago
<@465923409973477386> kapa.ai is still learning and improving, please let us know how it did by reacting below