T
TanStack3y ago
rival-black

reactive setDefaultsOption not working

This is code I have in main +layout.svelte. I expect refetchInverval to be updated every time my store value changes, but its not
No description
12 Replies
rival-black
rival-blackOP3y ago
It's only initialized with initial value e.g 10 on first render and then does not change at all, despite $dataRefetchInterval is bind to input and Im changing its value moreover this reactive scope is triggered every time dataRefetchInterval change, console.logs are working and so on @Raytuzio maybe you would be able to help? thanks
vicious-gold
vicious-gold3y ago
I'll be honest, I don't understand classes at a deep level, but I'm assuming this is because we are initialising something (new QueryClient) that can't be edited once created. I haven't seen this done with react-query before either.
vicious-gold
vicious-gold3y ago
Oh sorry I misread the code above - yeah that seems like it should work. I'll have a look!
rival-black
rival-blackOP3y ago
It looks like new interval value is being applied, but query itself does not react to changes - new interval is used when query is unmounted and mounted again I checked if queryClient.resetQueries({ type: 'active' }); after changing defaultOptions would work, but is not. Not sure if its bug? Is there any workaround?
vicious-gold
vicious-gold3y ago
Yeah, I can see the bug. Can you make an issue on GitHub?
rival-black
rival-blackOP3y ago
Of course. Is this kinda quick fix? Or more hard problem?
vicious-gold
vicious-gold3y ago
GitHub
query/packages/svelte-query/src/createBaseQuery.ts at 047005e13485a...
🤖 Powerful asynchronous state management, server-state utilities and data fetching for the web. TS/JS, React Query, Solid Query, Svelte Query and Vue Query. - TanStack/query
vicious-gold
vicious-gold3y ago
If you manually pass in a queryClient to createQuery, you might be able to make it work.
rival-black
rival-blackOP3y ago
in react client is probably rerendered everytime default settings changes, so maybe in svelte useQueryClient should also return reactive store?
No description
rival-black
rival-blackOP3y ago
but im not very familiar how all this works under the hood
rival-black
rival-blackOP3y ago
@Raytuzio hope its correct and enough descriptive: https://github.com/TanStack/query/issues/5855
GitHub
Svelte query - query does not react to changing default options by ...
Describe the bug I have initialized QueryClient in main +layout.svelte: const queryClient = new QueryClient({ defaultOptions: { queries: { enabled: browser, refetchInterval: $dataRefetchIntervalS *...

Did you find this page helpful?