Replies: 1 comment 1 reply
-
could you forward where you are coming from to the File component, like:
Then the |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to decide on the best way to share cached data between two different queries, or if I'm going about this all wrong. Below is a description of the problem and the solution I'm considering, is this insane? Is there a better way to do this? I currently use SWR, but would gladly switch to React Query if it can solve this in a nicer way.
The problem
For the purpose of this question, our app is a file viewer. The user can view a list of files either by directory listing or by executing a search. Then, they can open a file in a viewer component. The queries return a list of files, and we use react-dnd to let the user drag and drop the
file
object onto the viewer component (DropTarget):However, there are Reasons™ that I'd like to stop sending the whole
file
in the drag object, and instead just send the file's ID. Then, the drop target would look up the item in the cache:I know the docs suggest doing something like
queryClient.getQueryData('todos')?.find(d => d.id === todoId)
, but I don't know the exact query key that was used. The query key used to display the list is different depending on whether I came from DirectoryListing or SearchResults. So, I don't know what would replace the "???" above.My possible solution
I could also cache files under a key
["file", id]
. I thought about setting this in theonSuccess
handler:Then I can
queryClient.getQueryData(["file", id])
in the drop target.So, that's the gist of my scenario, is this a reasonable solution? It feels like something I might regret later.
Additional information
Why can't you pass the whole
file
object?This is a simplified description of our app. Once a file is dropped onto the DropTarget, the user can then copy the
file
from the DropTarget into a third area, let's call it the "Workspace".The problem is that
file
might have been updated by the DirectoryListing. I'd like the latest copy offile
to be used in Workspace. And Workspace isn't really structured in a way that makes it possible to calluseQuery(["file", id])
there.Beta Was this translation helpful? Give feedback.
All reactions