Research other data fetching strategies in the frontend #2811
tillprochaska
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Some features in Aleph have quite complex UI interactions and are very interactive, for example network diagrams. Then there are many screens/views in Aleph, that are very simple in terms of interactivity - most of the time, we load some data from the API and display it. Sometimes users can even fill out a form and the contents get posted to the API :D
On a high level, this is more or less what we do:
redux-act
andredux-thunk
) is used for the main app store.EntityManager
) for historical reasons. When we still supported Aleph Data Desktop, we wanted to have a set of shared UI components that do not rely on a Redux store.Some aspects of this are quite cool, but there are also disadvantages to this approach:
In recent years, we’ve seen things in this area change quite a bit. Frameworks like Next.js and Remix have reduced the complexity of loading data for the 80% of simply CRUD-like use cases. Even without Remix or Next, there are now a few interesting options:
SWR
SWR exposes a hooks API to fetch data in components, while making sure that no duplicate requests happen, data is cached an invalidated properly etc.
In the simplest case, data can be fetch from an API endpoint using the
useSWR
hook:It’s easy to build reusable hooks in case the same data is required in multiple components:
SWR ensures that only a single API request is sent, even if the
NavBar
andProfilePage
components are rendered on the same page or when re-renders happen. It also has support for long polling, mutations/invalidation, infinite scrolling, …React Router
React Router v6 has added declarative data loading for routes. Every route can define an async loader that is executed when a user navigates to the route. The return value of the loader is accessible using hooks:
React Router also has support for mutations and invalidations. It’s agnostic with regards to the way of sending API requests (vanilla fetch, SWR, Axios, …).
React Query
React Query
TODO
Beta Was this translation helpful? Give feedback.
All reactions