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
How to invalidate and refetch query? #15
Comments
Hi @acoustep . First of all, thanks for using this lib in your project. It really means a lot to me! import SwiftUI
import Combine
import Pigeon
struct ContentView: View {
@StateObject private var queryA = Query<Void, String>(
key: .keyA,
fetcher: {
Just("A")
.mapError { $0 }
.handleEvents(receiveOutput: { (value: String) in
print("Received value from queryA", value)
})
.eraseToAnyPublisher()
}
)
@StateObject private var queryB = Query<Void, String>(
key: .keyB,
fetcher: {
Just("B")
.mapError { $0 }
.handleEvents(receiveOutput: { (value: String) in
print("Received value from queryB", value)
})
.eraseToAnyPublisher()
}
)
var body: some View {
VStack {
Button("Query A", action: {
queryA.refetch(request: ())
})
Button("Query B", action: {
queryB.refetch(request: ())
})
Button("Invalidate Query A", action: {
QueryInvalidator()
.invalidateQuery(for: .keyA, with: .lastData)
})
Button("Invalidate Query B", action: {
QueryInvalidator()
.invalidateQuery(for: .keyB, with: .lastData)
})
}
}
}
extension QueryKey {
static var keyA: QueryKey { .init(value: "A") }
static var keyB: QueryKey { .init(value: "B") }
} Using |
I'll close this issue. If you have any other problem, please let me know and I can reopen it! Thanks! |
Hi!
Thanks for this great library. I have it mostly working, but I'm struggling with one issue.
I'm trying to invalidate and refetch data when a user does an action. I can see there is a way to do with this with mutations in the docs but I can't seem to do it with a Query.
I have tried using UserDefaultsQueryCache.shared.invalidate(for:), but nothing seems to happen.
Here's what I have so far, I'm using a pull down library which I'm trying to trigger the refresh.
Thanks for any guidance you can give.
The text was updated successfully, but these errors were encountered: