API Options
Constructors:
// Simple JSON Object decoder@SWR<URL, Model>(url: "https://example.org/api/endpoint", options: SWROptions = .default) // Where Model can be any Codable struct.// Raw Init - You should use this only if you want to have a custom workflow@SWR<Key, Value>(key: Key, fetcher: Fetcher<Key, Value>, options: SWROptions = .default) // Where Key is a hashable that can represent the query and Value is the returned object.
Return Values
You'll receive a StateResponse<Key, Value>
object that has the following properties:
data: Value?
: data for the given key resolved by fetcher (ornil
if not loaded)error: Error?
: error thrown by fetcher (ornil
)awaiting: Bool
: is the request still happening?revalidate(mutated: Value? = nil, makeRequest: Bool = true)
: function to mutate the cached data
Options
autoRefresh = false
: auto revalidate data every 15 secondsrevalidateOnFocus = true
: auto revalidate when window gets focusedrevalidateOnReconnect = true
: automatically revalidate when the user regains a network connectionrefreshWhenHidden = false
: polling when the window is invisible (ifrefreshInterval
is enabled)refreshWhenOffline = false
: polling when the user is offline