carson-katri / swift-request

Declarative HTTP networking, designed for SwiftUI
MIT License
727 stars 41 forks source link

How to refresh a RequestView? #18

Closed lvscar closed 4 years ago

lvscar commented 4 years ago

swift-request is brilliant , especially when using it with SwiftUI.

But I can't find a way to refresh a RequestView , cloud you give me some clue?

Thank.

carson-katri commented 4 years ago

Sort of a workaround, but to make something redraw in SwiftUI you need to update the State. You could add a query param and update it when you want to refresh it. Something like:

struct ContentView : View {
    @State private var refresh: Int = 0

    var body: some View {
        VStack {
            Button(action: { self.refresh += 1 }) { ... }
            RequestView(Request {
                ...
                Query(["refresh": refresh])
            }) { ... }
        }
    }
}