How it works
Gravity provides critical functionality in all kinds of SwiftUI apps, so performance is a top priority.
Gravity’s built-in caching and deduplication skips unnecessary network requests, but
the performance of the SWR
hook itself still matters. In a complex app, there could be hundreds of SWR
calls in a single page render.
Gravity ensures that your app has:
- no unnecessary requests
- no unnecessary re-renders
- no unnecessary data revalidation
without any code changes from you.
Deduplication
It’s very common to reuse Gravity hooks in your app. For example, an app that renders the current user’s avatar 5 time. Each Avatar
view has a SWR
hook inside. Since they have the same key and are rendered at the almost same time, only 1 network request will be made. Same goes with GravityStream
, where only one WebSocket connection will be active. One thing that is great about Gravity, is that even though 1 connection will be active, you can use different data processor, as WebSockets can transfer different type of information.