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

Is there a way to access the "currentData" of lazy query trigger result? #4746

Open
maxkostow opened this issue Dec 2, 2024 · 3 comments
Open

Comments

@maxkostow
Copy link

See this example: https://codesandbox.io/p/sandbox/xenodochial-river-p9d6nj which demonstrates that the lazy unwrap returns the cached value.

The docs for lazy query say that if you need the immediate access to the result you should call .unwrap() however, this returns the cached value instead of the result of the lazy query. Is there a way to await the value of the newly initiated fetch?

@maxkostow maxkostow changed the title Is there a way to access the "currentData" of lazy query? Is there a way to access the "currentData" of lazy query trigger result? Dec 2, 2024
@phryneas
Copy link
Member

phryneas commented Dec 2, 2024

If you pass false as the second argument (preferCacheValue), you get what you want:

await getPost(1, false).unwrap()

@maxkostow
Copy link
Author

maxkostow commented Dec 2, 2024

I believe false is the default value for preferCacheValue (the docs say to pass true "if you want it to immediately return a cached value if one exists"). I updated the example to pass false and it exhibits the same behavior.

@phryneas
Copy link
Member

phryneas commented Dec 2, 2024

That's irritating, I tested it and it worked. I did update RTK by one major and four minors, though, maybe try that?

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

2 participants