-
Notifications
You must be signed in to change notification settings - Fork 4
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
Storing previous results of a query in SwiftUI view #10
Comments
I think you can do what you want here by using onChange and/or onAppear to do the assignment to the A different pattern I've used for searching is to use separate state for the text the user is entering and the text being used to query, only update the latter once the user has stopped typing for a short amount of time. Here's an example of a view where I did that. That may not be the pattern you want to use for your app, but it does have the benefit of not having to hang on to a previous list of search results. |
Thanks for the pointers!
so using More than just the search UI, I also wanted to pre-fetch some thumbnails based on the search results. I can do that in the |
I'll have to give this some thought. If you really want to manage the lifecycle of the query results yourself, you may be better off using fetchQuery manually. By doing so, you wouldn't automatically update your view when the records changed (like in mutations), but maybe that's okay for something like search results. I've never implemented this pattern, so I'm not sure what gotchas you might hit. As far as fetching thumbnails, I think I've generally opted to delegate that to a child view like you mention. There's features in Relay for JS I think for extending a schema with client-side-only fields, which could maybe help with this, but I haven't implemented that in Relay.swift yet. |
I have a view with a search bar and a query to fetch the results. It all works great, but I'd like to store the previous results so that when you type, you don't jump into the "loading" state as the query executes.
I was trying something like this:
But then get an error about modifying state during view update and the UI hangs when typing. Is it possible to subscribe to the query results in some way to do this or given this custom behavior, should I just directly call
fetchQuery
?The text was updated successfully, but these errors were encountered: