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

12 Replies
rival-blackOP•3y 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•3y 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.rival-blackOP•3y ago
vicious-gold•3y ago
Oh sorry I misread the code above - yeah that seems like it should work. I'll have a look!
rival-blackOP•3y 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•3y ago
Yeah, I can see the bug. Can you make an issue on GitHub?
rival-blackOP•3y ago
Of course. Is this kinda quick fix? Or more hard problem?
vicious-gold•3y ago
Not 100% sure yet - I need a way to make this line reactive: https://github.com/TanStack/query/blob/047005e13485afb5d637e746a67cdaae8a8fe551/packages/svelte-query/src/createBaseQuery.ts#L33
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•3y ago
If you manually pass in a queryClient to createQuery, you might be able to make it work.
rival-blackOP•3y ago
in react client is probably rerendered everytime default settings changes, so maybe in svelte useQueryClient should also return reactive store?

rival-blackOP•3y ago
but im not very familiar how all this works under the hood
rival-blackOP•3y 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 *...