dependent-tan
dependent-tan5mo ago

useSelect seems to ignore cached values.

I have quite simple useSelect, which fetches tenants. I use global config reactQuery: { clientConfig: { defaultOptions: { queries: { staleTime: 5 * 60 * 1000, }, }, }, } I use the hook: const { selectProps: tenantSelectProps, queryResult } = useSelect({ resource: "tenants", optionLabel: "name", }); <Select {...tenantSelectProps} /> Now, when entering the page first time and rendering component tenant select loads with correct values, like it should. But when closing the page and returning to it (tenant list should be loaded from cache) - the select is empty. If I disable staleTime in Refine global config of-course select populates, but tenants are fetched from network every time. When I do this: const options = queryResult.data?.data.map((item: any) => ({ label: item.name, value: item.id, })); <Select {...tenantSelectProps} options={options} /> it works expected fetches first time, and subsequently loads from cache. Does useSelect ignores values fetched from cache ?
2 Replies
kapa.ai
kapa.ai5mo ago
Hi @duneatnight. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the information provided in the extracts, useSelect hook in Refine uses React Query for data fetching and caching. By default, Refine has 5 minutes of cache time and 0 seconds of stale time for queries. This means that if a query is re-used in 5 minutes, it will be populated with cached data and in the meantime, it will be refetched in the background. If the query is not re-used in 5 minutes, it will be refetched immediately. However, there's no explicit information in the extracts that suggests useSelect ignores values fetched from cache. It's possible that the issue you're experiencing might be related to a specific implementation detail or a bug. I would recommend checking the Refine documentation (https://refine.dev/docs/guides-concepts/general-concepts#state-management) and useSelect documentation (https://refine.dev/docs/data/hooks/use-select) for more information. If the issue persists, consider reaching out to the Refine community or support for further assistance. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@1051552034823872643> kapa.ai is still learning and improving, please let us know how it did by reacting below