You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+67Lines changed: 67 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -62,3 +62,70 @@ This project was started as a Next.js application with server-side rendering hos
62
62
* If after all that you manage to get things to compile, you might notice you don't get **live data** everywhere, some pages simply don't update on reload... This is because those pages haven't been converted to client components yet! **When a server component gets compiled as static site, all server-side data fetching gets baked into the output!** This means you can refresh as much as you want, the data will always remain the same as what it was when the project was built. So, the solution?
63
63
**Convert everything to client components!**
64
64
65
+
## DataState Library
66
+
Since this project is handling a lot of async data that has to be fetched from API providers, I co-developed the DataState library to make all of this simpler, more intuitive, and without the usual bloat that comes with client-side data fetching.
67
+
68
+
The library mainly consists of a `DataState` Algebraic Data Type, which always is in either of 3 states:
69
+
-`LoadingState`: The data is still being fetched.
70
+
-`ErrorState`: The fetching process ran into some kind of error. The `error` field contains the `Error` object.
71
+
-`ValueState`: The fetch succeeded, and the resulting data is contained inside the `value` field of the DataState.
72
+
73
+
More specifically, the DataState consists of a `Root`, which contains the actual data fields, and `DataStateMethods` that extend the `Root` object into a full `DataState`.
As shown above, every DataState has a `.Render()` function that receives the fetched data as input, allowing the use of the fetched data directly inside the JSX code:
130
+
* Obviously, the Render function only renders the actual data when it is present. If not present, it will render either an `ErrorIndicator` indicating the error that occurred, or a `LoadingIndicator` or `LoadingPulse` component when the data is still being fetched.
131
+
* All of this is very configurable; see the `RenderConfig` type in `src/lib/data-state/types/index.ts` on line 107. The `RenderConfig` only consists of optional fields to configure the `Render()` function's output. This means the `<blockData.Render>` component's props are all optional, and you can pick and choose only the ones that you need.
0 commit comments