Get fetched data in another component
I have this hook:
Here i set the query:
And here i want to use the data and also update it when a new search is done:
6 Replies
stormy-gold•3y ago
What is your question?
Ah, got it. To access the cache entry you need to know the key, in your case
[’users’,{query}].
So in UserResults you also need to pass query into your hook. Maybe prop drilling or a global state might be suitable for youother-emeraldOP•3y ago
Ah ok i tought i would dont need to add the query in the userResults, i tought i could get the data with only the key, the problem is i cant send props cause the components is not connected, maybe i could add a context to my hook and set it equal to the data?
So i should call it in my UserResults something like?
stormy-gold•3y ago
No, just
query, like in the other component.other-emeraldOP•3y ago
Ok but when to use the key?
stormy-gold•3y ago
Your problem is very basic. Did you read the documentation?
foreign-sapphire•3y ago
use set enabled: !!query it mean when query is falsely value it will fetch data unless enabled true so query key also change when query change it treat key as deps useEffect
please read documents more