Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RTK Query] Reset state for lazy query, similar to mutation #4834

Open
Tasin5541 opened this issue Jan 29, 2025 · 0 comments
Open

[RTK Query] Reset state for lazy query, similar to mutation #4834

Tasin5541 opened this issue Jan 29, 2025 · 0 comments

Comments

@Tasin5541
Copy link

Having a reset option for query would definitely help. Take for example, we have a derived variable that reads from the result of 2 queries (whichever is present or the latest one fetched).

const { trigger1, { data: data1 } } = useData1LazyQuery();
const { trigger2, { data: data2 } } = useData2LazyQuery();
const derVal = data1 || data2 || null

We need the derVal to always point to the latest data. If data2 is fetched after fetcing data1, derVal should be data2.

Having an option to reset the other query's state during triggering one query would definitely be the best approach here.

const { trigger1, { data: data1, reset: reset1 } } = useData1LazyQuery();

// trigger data2 handler
reset1(); 
trigger2();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant