-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
V3 Umbrella Issue #772
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
Comments
Would be nice to address this somehow in v3 #669 |
@tannerlinsley is there any support for class components for react? not directly but rendering a functional component with query hooks into a class component. |
For V3, I'd propose allowing extending the Use case: I am writing test utilities that allow you to mock named queries and right now the To handle this, I have to mutate the queryCache that comes back to override methods when it would be nicer to extend class TestQueryCache extends QueryCache {
// override member methods as-needed
}
const testQueryCache = makeQueryCache(TestQueryCache);
// or queryCaches.push(testQueryCache) could also probably work
// but this leaks implementation details At the crux of this I am looking for a way to intercept cache gets and sets, so any way to accomplish the same thing would work as well. 👍 |
@tannerlinsley |
@kamranayub in the latest version the |
Aw bummer I like how the global queryCache does not use Context. How will we access the queryCache in our custom hooks then? Or set the queryCache programmatically for fetch-as-you-render? Also I'm working on a lib that behaves like Zustand (global state) but uses regular hooks. I was excited by the prospect of being able to actually use the two libs together elegantly instead of just using them side-by-side. |
Would there be any interest in allowing a zustand-like Something like this: // All data
const { data: { count, items, limit, offset} , isLoading, isSuccess, } = useQuery('items', () => fetch('/api/items'))
// Just the count
const { data: count, isLoading, isSuccess, } = useQuery('items', () => fetch('/api/items'), { select: s => s.count }) |
Oh looks like this may be something that could happen: #883 (comment) |
@timkindberg, the Yes we have discussed selectors a bit. We'll have to see how that conversation progresses. |
@timkindberg best way to access a query cache in custom hooks is with |
Are there any particular recommendations that we should know about to use in place of |
Can we address #991 in V3? |
Hi @tannerlinsley, is there any more context around these todo items? Particularly, I'd be interested to know why |
|
Thank you @razh! |
I documented an unnecessary render that is happening when the query first mounts and can theoretically know that it needs to rerender to set https://codesandbox.io/s/currying-dust-dom4u?file=/src/App.js Edit: Maybe I misunderstood this change because it's under the QueryCache and not the Query section, but I am still curious about whether the above issue can be solved. |
I forked your sandbox with V3 and it seems to resolve the issue: https://codesandbox.io/s/kind-cookies-6l56e |
How can I test v3? As per Tanner's tweet |
I'm using MyApp.getInitialProps = async () => {
await client.prefetchQuery(
'posts',
() => {
// return fetch()
},
{
cacheTime: Infinity,
},
);
} Some where const posts = client.getQueryData('posts'); |
Hi @nghiepit! Can you provide some more code and create an issue? |
It seems 2.40+ releases are already targeting the v3 changes. Consider fixing the release versions to avoid confusing people. |
We’re aware. Working on a fix. At least they’re on the beta channel. If you’d like to submit a PR to help fix it, feel free. |
Just an idea: |
We did this in our App and I would suggest avoiding it. Different browsers / user settings impose different limits on what and how much can be stored on the browser. Hitting those limits would cause exceptions at best and subtle unexpected behavior at worse |
Looks like v3 is going to be about 10k(minified) larger than v2 according to https://bundlephobia.com/[email protected] With gzip I realize it's only an extra 1kb, but it's still a hit to low-end mobile when keeping bundle size low is becoming harder. Is there a size target y'all are aiming for? |
@greggb, we're always trying to keep good tabs on the size, since that's one of it's features when compared with apollo and other similar libraries. Even with the addition of the parsed 10kb, we're still well under what most other libraries are. For the future, if and when bundle size takes a giant leap, we're fully prepared to break out the library into separate bundles (much like the hydration api is now) and let users only import what they need. |
@tannerlinsley Thanks Tanner. Reassuring to hear it's a priority for the library. 🤗 |
If you need any help with the v3 work, I'd enjoy to contribute - I would just need a little guidance on where to start. 😄 |
Imagine you have REST API client instances, you use to make requests, but in tests (or during development if API is not yet implemented...) you want to replace all clients with fake ones. |
In my project I use msw to mock the whole API. It is useful to use in the test and also for prototyping when running in dev. There is the advantage of avoiding mocking any implementation in your code. This can be an option. |
Nice one, but there are other use cases where mocking solution of this sort is not sufficient. As I was going through API reference It came to me I can use queryFnParamsFilter to add extra argument (service container) to my queryFns. This is what I was looking for even thou it seems weird to add something in function called like that. |
@timkindberg re: selectors. 👍 We have a wrapper factory we wrote for our lib-specific query implementation that actually uses Reselect so we actually hide import { useCurrentUser, selectAddress } from '@data/users';
const { select } = useCurrentUser();
const address = select(selectAddress); I like the idea of this being built-in to react-query (or as an extension) because when you use a selector ideally you'd only want the hook to cause a re-render if that selected data has changed whereas right now it'll change when |
all points seem to be checked, any planned date for official v3 release? |
Hi there 👋, I'm wondering if it would make sense to allow the Take an example like the one from the Query Function Variables doc:
In typescript I would define
However, accessing the variables with I wish I could do something like this:
Does that make sense, or am I missing another way around this? Thanks for the great repo! |
Hi @dougmacklin! Inline query functions are preferred, but I added the possibility to type the query key |
Wow thanks for the quick addition @boschni! When you say "inline function are preferred", do you mean it would be better to just do something like:
and avoid extracting the query key altogether? |
Np! Yeah either like that or create a function like |
Is v3 better for new users? |
I have completely broken typing with v3 and can't get why. Eg, |
Uh oh!
There was an error while loading. Please reload this page.
Below are the official breaking changes and features for v3. If you have a feature request or idea, please use the Discussions tab to open a new discussion about that idea.
Global:
Query:
QueryCache:
ReactQueryCacheProvider
QueryObserver:
Query Config:
The text was updated successfully, but these errors were encountered: